【发布时间】:2016-05-21 01:28:22
【问题描述】:
我有一个固定宽度的左 div,我想让右 div 填充剩余空间。
到目前为止,我一直是taking this approach recommended by another SO poster,但如果我在正确的 div 中有内容,它就不起作用。
右侧div中的内容设置为width: 100%,所以我希望它不会比右侧div宽,但它会溢出右侧div。
<div>
<div id="left">left</div>
<div id="right">right<div id="insideright">overflows</div</div>
</div>
<style>
#left {
float:left;
width:180px;
background-color:#ff0000;
}
#right {
width: 100%;
background-color:#00FF00;
}
#insideright {
width: 100%;
background-color: blue;
height: 5px;
}
</style>
这里是JSFiddle,演示问题:http://jsfiddle.net/MHeqG/155/
我能做什么?
我想支持较旧的 IE 浏览器,所以如果可以避免的话,我宁愿不使用 display: table-cell 等,或者至少在没有合理回退的情况下不使用。
【问题讨论】:
-
您能否通过引用您正在谈论的 div 的实际 id 来澄清您的问题? “右侧 div 中的内容...”哪个右侧 div?
-
请定义“旧浏览器”
-
它会溢出,因为您将其宽度属性设置为浮动元素旁边的 100% 屏幕。它一直持续下去,因为没有任何因素可以阻止它。你应该在浮动后使用明确的修复
-
你想一起避免溢出还是只溢出到最左边?