【发布时间】:2014-10-14 05:36:41
【问题描述】:
我在使用 display: table 和 display: table-cell 时遇到问题。
提琴:http://jsfiddle.net/5q51sbqb/1/
我有一个带有 display:table 的 div;并在这两个 div 中显示:table-cell;
左边的 div (.t1) 是固定宽度,右边的 div(.t2) 应该占据容器边缘的剩余空间。
我的问题在于在右侧 div(.t2) 中添加一个长 div (2000px)。我基本上需要内容窗口与其父窗口保持相同的宽度,而不会超出容器的范围,以允许滚动其中的内容。
请记住,这需要不使用固定宽度,因为容器和 t2 都是响应式的。而且我还必须使用表格和表格单元格显示属性:(
所以基本上 .t2 div 的子项在我需要它们以适应容器宽度时超出容器(无需在内容窗口上设置固定宽度......和 .t2 div 上)
我被难住了。
HTML
</div>
</div>
<div class="table-cell t2">
<div id="content-window">
<div id="content"></div>
</div>
</div>
</div>
</div>
CSS
#container{
width: 600px;
height: 600px;
margin: 0px auto;
background-color:green;
padding: 2px;
}
#table{
display:table;
width:100%;
}
.table-cell{
display:table-cell;
height: 300px;
padding:2px;
}
.t1{
width: 100px;
background-color: red;
}
.t2{
width:auto;
background-color: blue;
}
#content-window{
width:100%;
overflow:scroll;
}
#content{
width: 2000px;
height: 50px;
background-color:yellow;
}
【问题讨论】: