css - 强制绝对 div 听 parent 的填充?

标签 css html

这是我的 HTML/CSS 当前的样子:

enter image description here

这是我想要它的样子:

enter image description here

我如何修改下面的 HTML/CSS 以使其显示我想要的样子?

HTML:

<div id="panel">
    <div id="bottom">
        <div class="update"></div>
    </div>
</div>

CSS:

.update {
    width: 100%;
    background-color: #006699;
    text-align: center;
    height: 56px;
    color: white;
}

#bottom {
    position: absolute;
    bottom: 20px;
    width: 100%;
    left: 0;
}

#panel {
    width: 21.25%;
    height: 100%;
    background-color: #0794ea;
    float: left;
    padding: 0 1.5%;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    position: relative;
}

谢谢

最佳答案

您可以使用包装器解决问题

您的 HTML 看起来像这样:

<div id="panel">
    <div class="wrapper">
        <div id="bottom">
            <div class="update">
                a          
            </div>
        </div>    
    </div>
</div>

还有你的 CSS:

#panel {
    width: 21.25%;
    height: 100%;
    background-color: #0794ea;
    float: left;
    padding: 0 1.5%;
    box-sizing: border-box;
}

.update {
    width: 100%;
    background-color: #006699;
    text-align: center;
    height: 56px;
    color: white;
}

.wrapper {
    position: relative;
    height: 100%;
}

#bottom {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    background: yellow;
}

这是一支带有最终结果的笔:http://codepen.io/DanielVoogsgerd/pen/Lezjy

关于css - 强制绝对 div 听 parent 的填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17923153/

相关文章:

CSS3 形状问题 - 混合模式乘法

html - 当具有不同高度时,如何将具有 flex 布局的 div 彼此向下放置?

html - UL 元素在 Firefox 中呈现不同

css - 将导航栏居中……

html - 如何为内部带有文字的几何形状创建内部阴影?

javascript - Flexslider 2.1 内联样式问题

html - 固定导航栏

html - 在浏览器调整大小时移动图像

javascript - 多个html5音频元素Jquery错误

html - 消息元素导致父元素展开