html - float div 不考虑高度值的问题

标签 html css

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

我有两个 div,在 body 内左右浮动;右边的 float div 设置为“高度:100%”,因为我想要一个插入框阴影,我用它来明显地分割两个 div 的内容。只要左侧 div 中的内容长度不足以导致页面需要滚动条,所有这些都可以正常工作,一旦发生这种情况,右侧 float 的 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);
}

最佳答案

改变

float: right;

在右侧面板 到

display: inline-block;

这为阴影提供了 100% 的高度。

喜欢这个 fiddle :http://jsfiddle.net/yw3vLess/5/

关于html - float div 不考虑高度值的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26840908/

相关文章:

html - 如何在div中正确使用padding?

jquery - 添加 css 类在 jquery 中有时不起作用

CSS 图像位置

html - 带有全宽图像的 Bootstrap 4 容器

javascript - Z 索引 : neg value preventing me from targeting classes in jquery

javascript - 无法捕获 HTML 字符串中元素的单击事件

javascript - ul 溢出-x : visible and overflow-y:scroll doesn't work at same time

html - 如何将小图片列表的方向从大型桌面的一列更改为手机的一行?

html - 带有 Bulma CSS 的 Angular 6 呈现没有 Bulma 样式的 HTML 元素

javascript - 为什么悬停事件不能与 Bootstrap 选项卡上的 jquery 方法一起使用?