javascript - Firefox 忽略填充底部与 box-sizing :border box

标签 javascript jquery html css

Firefox 忽略 padding-bottom with box-sizing:border box。 我正在尝试将两个子 div 放入 300px 的容器 div 中。 child1 - 高度 100%; child2 - 从底部高度 100px;

child1 有 border box 和 padding-bottom:100px 这应该将 child1 的高度降低到 (100% - 100px) 让位给 child2。 此实现在 webkit 中运行良好,但 firefox 失败。 有解决办法吗?我不想使用 css calc()。

这里是例子 - http://jsfiddle.net/827D6/1/

使用的CSS:

.container{
 height:300px;
 width:300px;   
 background-color:black;
}
.child1{
    height:100%;
    background-color:red;
    position:relative;
    padding: 20px 20px 100px;
    box-sizing: border-box;
    overflow-y:auto;
    word-wrap:break-word;
}
.child2{
    height:100px;
    position:relative;
    background-color:green;
    bottom:100px;
}

最佳答案

您可以轻松地使用绝对位置。只需将容器设置为relative 并将第二个 child 的高度设置为bottom:0。然后将第一个 child 设置为 top:0;bottom:100px;

.container {
    position:relative;
    height:300px;
    width:300px;
    background-color:black;
}
.child1 {
    background-color:red;
    position:absolute;
    top:0;
    right:0;
    bottom:100px;
    left:0;
    padding: 20px 20px 0;
    overflow-y:auto;
    word-wrap:break-word;
}
.child2 {
    height:100px;
    position:absolute;
    right:0;
    bottom:0;
    left:0;
    background-color:green;
}

DEMO

关于javascript - Firefox 忽略填充底部与 box-sizing :border box,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23622257/

相关文章:

javascript - 如何使用 pidCrypt 进行 AES CBC 加密,然后使用 phpseclib 解密?

javascript - 如何使用 JQuery 验证特定 div 中的复选框?

jquery - 使用 FullCalendar 和 removeEvents 方法过滤 onclick 事件

html - 为什么我的表没有行?

javascript - 如何为任何移动设备在 html 中设置图像

javascript - 页面上的多个 ng-app 指令

javascript - 如何在 JavaScript 中获取字符的 ASCII 值

javascript - 停止传播不工作 Jquery

javascript - 用于过滤无模式集合的最快数据结构

javascript - 在 jQuery Mobile 中打开弹出窗口时如何避免上下滚动