【问题标题】:Trouble with floated div not respecting height value浮动 div 不尊重高度值的问题
【发布时间】:2014-11-10 18:23:44
【问题描述】:

我有一个使用各种表格显示值的页面,试图让我的页面正文自动填充页眉和页脚之间的空间。

我有两个浮动的 div,左右浮动;右侧浮动 div 设置为“高度:100%”,因为我想要一个插入框阴影,我用它来明显地分割两个 div 的内容。只要左侧 div 中的内容没有变得足够长以导致页面需要滚动条,所有这些都可以正常工作,一旦发生这种情况,右侧浮动 div 似乎不尊重它的高度值,并恢复到它的高度由它的内容决定。

jsFiddle 在哪里工作:http://jsfiddle.net/ec3upxk7/4/

它停止工作的地方:http://jsfiddle.net/yw3vLess/2/

这是工作代码:

HTML:

<div class="container">
    <header class="header">
        <p>This is the header</p>
    </header>
    <section class="content">
        <div class="content-body">
            <div class="left-panel">
                <p>This is the content.</p>
            </div>
            <div class="right-panel">
                <p>This is not the content.</p>
            </div>
        </div>
    </section>
    <footer class="footer">
        <p>This is the footer.</p>
    </footer>
</div>

CSS:

/* Reset */
html, body { height: 100%; margin: 0; padding: 0; }

/* Essentials */
.container { display: table; }
.content { display: table-row; height: 100%; }
.content-body { display: table-cell; }

/* Aestetics */
.container { width: 100%; height: 100%; }
.header, .footer { padding: 10px 20px; background: #f7f7f7; }
.content-body { background: #e7e7e7; }

.left-panel {
    width: 50%;
    float: left;
}

.right-panel {
    width: 49.9%;
    height: 100%;
    float: right;
    box-shadow:
        inset 10px 0px 5px -7px rgba(0,0,0,0.5);
}

【问题讨论】:

  • 它在 Firefox 和 ie11 中工作,顺便说一句。在 Chrome 中 - 不是。

标签: html css


【解决方案1】:

改变

float: right;

在右侧面板中 到

display: inline-block;

这使阴影具有 100% 的高度。

喜欢这个小提琴:http://jsfiddle.net/yw3vLess/5/

【讨论】:

  • 谢谢,很抱歉现在才回复您,这几天忙得不可开交。解决方案效果很好!
【解决方案2】:

你可以试试看;

http://jsfiddle.net/tallrye/yw3vLess/4

.container-height {
    display:table;
    padding-left:0px;
    padding-right:0px;
    width:100%;
}
.row-height {
    display:table-row;
}
.col-height {
     display:table-cell;
     float:none;
     width:49.9%;
 }

.col-top {
    vertical-align:top;
}

您可以在本文中阅读有关此方法的更多信息:

http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-columns-of-same-height

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-03
    • 2014-01-23
    • 2016-02-18
    • 2013-10-06
    • 2013-06-27
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多