2

我有一个用<li>元素构建的流体网格。

例如:

<ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
</ul>​

li
{
    border:solid 1px green;
    width: 100px;
    min-height:50px; 
    display: inline;
    margin: 10px;
    float: left;
}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

所以这看起来像:

-----------   -----------   -----------   
|         |   |         |   |         |
|         |   |         |   |         |
-----------   -----------   -----------

-----------   -----------   -----------   
|         |   |         |   |         |
|         |   |         |   |         |
-----------   -----------   -----------

万岁!

问题是当我在<li>拉伸高度的元素之一中添加内容时。我想结束这样的事情:

-----------   -----------   -----------   
| apples  |   |         |   |         |
| oranges |   |         |   |         |
| lemons  |   -----------   -----------
| cherries|
-----------

-----------   -----------   -----------   
|         |   |         |   |         |
|         |   |         |   |         |
-----------   -----------   -----------

但我实际上最终是这样的:

-----------   -----------   -----------   
| apples  |   |         |   |         |
| oranges |   |         |   |         |
| lemons  |   -----------   -----------
| cherries|
-----------   -----------   -----------
              |         |   |         |
              |         |   |         |
              -----------   -----------

-----------   
|         |   
|         |   
-----------   

嘘!

所以基本上,当其中一个 s 从上面的元素向下推时,我试图保持“行”对齐<li>,而不是推到右侧的可用空间。

4

1 回答 1

2

看看下面的代码。

显然 IE hacks 和 moz 规则应该移到条件样式表中,并且存在一些填充问题(阅读:使用 css 重置

但除此之外,这应该可以解决问题....

替代文字 http://img835.imageshack.us/img835/9594/example1281542227415.png

例子

    <style type="text/css">
        ul {
            background-color:#ddddff;
            overflow:auto;
            margin:0;
            padding:0 0 0 4px;
            width:296px;
        }

        li {
            background-color:#ddffdd;
            display:inline-block;

            /* Trick FF2 into using inline-block */
            display:-moz-inline-stack;

            /* Trick IE6 into using inline-block */
            *display: inline;
            zoom:1;

            list-style-type:none;
            margin:0 0 0 -4px;

            /* Trick IE6 into enforcing min height */
            min-height:50px;
            height:auto !important;
            height:50px;

            padding: 0;
            vertical-align:top;
            width:100px;
        }

    </style>
</head>

<body>

    <ul>
            <li>apples<br />oranges<br />lemons<br />cherries</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
    </ul>

</body>

于 2010-08-11T16:29:47.623 回答