强制绝对div听父母的填充?

时间:2013-07-29 11:45:13

标签: 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;
}

由于

2 个答案:

答案 0 :(得分:10)

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

您的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

答案 1 :(得分:0)

在css中

* {
    box-sizing: border-box;
}