【发布时间】:2013-03-21 10:23:54
【问题描述】:
我有两个相邻的 div 框。包含“div 表”的左侧框。调整页面大小时,我希望隐藏左侧 div 表的内容,例如溢出:隐藏。 但是,左侧框包含“剩余”空间,而右侧框的宽度为 35%。
当 div 表格的内容比“剩余空间”(左框的宽度)宽时,表格的右边框不再可见。
我想隐藏图像的剩余部分,但仍然看到 div 表的右边框。这可以使用 div 表来完成吗?
HTML
<div class="table" id="containerRight">Some content on the right</div>
<div id="containerLeft">
<div class="table" id="tableLeft">
<div class="table-row">
<div class="table-cell">
<div style="width:14px;"></div>
</div>
<div class="table-cell">Some title</div>
<div class="table-cell">
<div style="width:14px;"></div>
</div>
</div>
<div class="table-row">
<div class="table-cell"></div>
<div class="table-cell">
<!-- This is the content of the LEFT table -->
<img src="http://oasis-church-nj.com/wp-content/uploads/2011/04/easter-egg.jpg" style="height:100px; width:500px;" />
</div>
<div class="table-cell"></div>
</div>
<div class="table-row">
<div class="table-cell"></div>
<div class="table-cell"></div>
<div class="table-cell"></div>
</div>
</div>
</div>
CSS
.table {
display: table;
overflow: hidden;
border-collapse: collapse;
}
.table-row {
display: table-row;
}
.table-cell {
display: table-cell;
word-break: all;
overflow: hidden;
}
#containerLeft {
background: #F0F;
position: relative;
display: block;
overflow: hidden;
margin: 0px 0px 15px 0px;
}
#containerRight {
background: #FF0;
position: relative;
min-width: 220px;
max-width: 400px;
width: 35%;
height: 300px;
float: right;
margin: 0px 0px 15px 15px;
}
可以在此处找到示例。让 HTML 表格变宽变小,右边框会消失。 http://jsfiddle.net/gqmJ9/
【问题讨论】:
-
边界?您是指洋红色背景色条吗?
-
将表格视为 9 个单元格,3 行 3 列。中心单元格是“内容”,而外部 8 个单元格是我定义为“边框”的单元格。当然,在最终代码中,它们将被填充图像以显示一个漂亮的框。
标签: html css html-table