我有一个问题。
如果我在内容 div 中有 2 个 div 元素,例如“左”和“右”。
我希望左边的 div 宽度为:250px;,右边的宽度为:auto;,所以如果我缩小它,右边的 div 适合浏览器窗口。这可能吗?
我试过了,右边的 div 跳到了左边的下面,而不是在右边。
.content {width:1000px;}
.left {width:250px;}
.right {width:auto;}
最佳答案
只需 float left div,并使用 right 的左边距将其从左侧 div 下方移除:
.left {
width: 250px;
float: left;
}
.right { margin-left: 250px; }
只需确保您有 cleared the float在容器的末尾。
例如:
.content:after { /* clearing the float */
content: '';
display: block;
clear: both;
}
另外,您可能想看看 Nicolas Gallagher 的 micro clearfix hack ,或 this topic在 SO 上。
关于html - 两个 div,一个规定宽度,一个未知。如何解决这个问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22113073/