我有两个float:左侧divs,设计为从左到右堆叠,一个是经典的左侧导航栏,并且声明了固定宽度。另一个设计为跨越浏览器的其余宽度,并填充剩余宽度的100%。目前它没有本地或任何js/jQuery声明的宽度。防止表格向下推浮动左侧div
问题出现在第二个div中有一个表格,其中有大约10列表格结果,其中一些表格结果较长。只要表格单元格的累积文本将表格宽度推到它所在div的大小,div就会在左侧导航栏下弹出。
是否有任何策略基本上“告诉表”,它不会展开比父div更广泛的范围,而是单元格中的文本会换行?我希望不必为此使用任何JS。
<div id="container">
<div id="leftNav" style="width:250px;">
left<br>nav<br>here<br>
</div>
<div id="mainContent">
<table>
<tr><td>about</td><td>10</td><td>Columns and they can contain sentences of text as well, but I'd like to not have the table push the div it's in down below the left nav div. This illustrates that point!</td></tr>
</table>
</div>
</div>
和CSS:
#container{
width:100%;
}
#leftNav{
float:left;
width:250px;
border:1px solid #ccc;
padding:15px;
}
#mainContent{
float:left;
background-color:aliceblue;
}
/* nothing more*/
没有看到任何代码,你可以只设置表{最大宽度: “一些宽度”} – 2014-10-01 01:44:04
同意托尼Tambe。 – 2014-10-01 01:45:43
如果你只关心对IE10 +的支持(如这个例子)(http://jsbin.com/vetuv/1/edit),你可以使用'calc()'。或[显示:表而不是浮动。](http://jsbin.com/tuhic/1/edit)IE8 + – misterManSam 2014-10-01 01:52:02