html - 不要根据旁边的元素拉伸(stretch)元素的高度

标签 html css height width

所以我有这个列表,其中包含 float 列表项,宽度等于 50%。它们都是动态生成的,有些 li 的高度比 wrest 更大,而旁边的 li 则延伸到那个高度,看起来有点奇怪。而且我不想让它拉伸(stretch)。这是我的代码:

HTML

<ul>
    <li>
        <span>Some label</span>
        Some text
    </li>
    <li>
        <span>Some label</span>
        Some text
        <ul>
            <li><strong>More options</strong></li>
            <li>Option 1</li>
            <li>Option 2</li>
            <li>Option 3 </li>
        </ul>
    </li>
    <li>
        <span>Some label</span>
        Some text
    </li>
    <li>
        <span>Some label</span>
        Some text
    </li>
</ul>

CSS

ul > li {
    float: left;
    width: 50%;
}

ul > li li {
    width: 100%;
    float: none;
}

JSFiddle -> https://jsfiddle.net/y160n4hg/

最佳答案

尝试这样: Demo

CSS:

#container {
    -webkit-column-count: 2;
    -webkit-column-gap: 0;
    -webkit-column-fill: auto;
    -moz-column-count: 2;
    -moz-column-gap: 0;
    /*  -moz-column-fill: auto;*/
    column-count: 2;
    column-gap: 0;
    column-fill: auto;
}
ul.one {
    list-style: none;
    margin:0;
    padding:0;
}
ul.one >li {  
    background:green;
    display:inline-block;
    width:100%;
    vertical-align:top;
}
ul.one li li {
    width: 100%;
    float: none;
    background:yellow;
}

ul.one li > ul >li {
    color: red;
    width: 100%;
    float: none;
}

HTML:

<div id="container"> <ul class="one">..</ul></div>

关于html - 不要根据旁边的元素拉伸(stretch)元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29669767/

相关文章:

html - 像表格一样显示的数据列表

php - 如何从 php 运行 html 文件?

html - 下拉列表 CSS

jquery - CSS、jQuery 坡度/倾斜菜单

html - 在 CSS 中使用 id.class 跨浏览器兼容吗?

html - 如何指定 PDF 大小?

html - 更高的 z-index 没有出现在元素上方

button - Flutter 更改 AppBar 内 OutlineButton 的高度?

javascript - 使图像高度为窗口高度的 1/4

javascript - 将一个高度加到另一个高度上