【问题标题】:Hide div table's content based upon remaining space根据剩余空间隐藏 div 表的内容
【发布时间】: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


【解决方案1】:

也许这就是你想要的:

http://jsfiddle.net/Bh8hg/1/

简单地为左边的 div 做了一个真正的边框。

#containerLeft {
    background: #F0F;
    position:   relative;
    display:    block;
    overflow:   auto;
    margin:     0px 0px 15px 0px;
    border:     #F0F 15px solid;    //real border
}

同时删除&lt;div style="width:14px;"&gt;&lt;/div&gt;, 将style 放在html 中不是个好主意,很难维护。

【讨论】:

  • 差不多,我现在也想用背景图像填充边界。添加了
    以表明图像的左右两侧确实有东西:)
猜你喜欢
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 2021-09-01
  • 1970-01-01
相关资源
最近更新 更多