html - 用多个列表元素填充水平列表

标签 html css

所以我需要制作一个水平列表,其中第一个列表元素具有固定宽度,最后一个列表元素应填充可用宽度。问题是最后一个元素填满了整行,即使我为第一个元素设置了 width。为什么第二个元素忽略了第一个元素的宽度?

html

<div id="wrapper">
    <ul>
       <li />
       <li />
    </ul>
</div>

CSS

#wrapper {
    width: 200px;
    height: 20px;
}

ul {
    display:table;
    width: 100%;
    height: 100%;
}

li:first-child {
    background:red;
    width: 30px;
}

li:last-child {
    background:blue;
    width: 100%;
}

li {
    display:table-cell;
}

最佳答案

在你的 JSFiddle 中,你告诉最后一个 li 元素应该使用整个宽度

li:last-child {
    width: 100%;
}

您可以省略 width 属性,因为它无论如何都会使用剩余的宽度。见修改 JSFiddle

关于html - 用多个列表元素填充水平列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20176731/

相关文章:

javascript - 使用 Javascript 添加一个类

javascript - 如何在按下按钮后禁用它,然后重新启用它?

CSS 布局问题。需要一双新鲜的眼睛

javascript - 本身工作得很好,但当我把它放在表格的其余部分时就会爆炸

javascript - 在不阻塞 dom 的情况下从后端渲染 ($compile) html 到 View 中

html - Ionic 3.x 中的样式 : Ion-Icon with gradient background colour (ion-chip)

html - 垂直和水平居中,同时遵守 flexbox 的 html 规则

html - 如何让 w3-cell 不自动调整?

javascript - SignalR 聊天 : Differentiating ListItem sender and receiver for Css

javascript - 菜单 acordeon : div stuck in my list because of the overflow