Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force absolute div to listen to parent's padding?

Tags:

html

css

This is what my HTML/CSS currently looks like:

enter image description here

Here is what I want it to look like:

enter image description here

How can I modify the HTML/CSS below so that it shows how I want it to?

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;
}

Thanks

like image 713
jskidd3 Avatar asked Jul 29 '13 11:07

jskidd3


1 Answers

You can fix the issue using a wrapper

Your HTML will look something along these lines:

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

And your 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;
}

Here is a pen with the end result: http://codepen.io/DanielVoogsgerd/pen/Lezjy

like image 99
Daniël Voogsgerd Avatar answered Oct 23 '22 14:10

Daniël Voogsgerd