HTML & CSS - Absolute positioned div overflows relative div, unexpected result

86 views Asked by At

I have an absolute positioned div(contains some text) within a relative div (contains an image) and it is set to bottom: 0px; however the absolute div is overflowing below the image. I cannot seem to fix this issue, I have tried applying overflow: hidden to the relative div.

Please see below for the issue https://jsfiddle.net/rebeccasmith1301/zzpxe767/

HTML

<div id="page-wrapper">
    <div id="footer-header-image">
        <div id="header-image-title">
            <h2>Some text</h2>
        </div>
        <img src="http://trustedfinance.co.uk/wp-content/uploads/2014/06/placeholder.png" id="apprentice-img"/>
    </div>
</div>

CSS

#page-wrapper {
    background-color: red; 
    height: 400px;
}

#footer-header-image {
    position:relative;
}
#header-image-title {
    position: absolute;
    left: 1.5%;
    bottom: 0px;
    z-index: 1000;
    background-color: rgba(255, 255, 255, .85);
    padding: 2% 1.5% 2% 1.5%;
}
#apprentice-img{
    width: 100%;
}
2

There are 2 answers

0
scgough On BEST ANSWER

There's some line height on the image. Try:

#apprentice-img{
    width: 100%;
    display:block;
}
0
gmast On

Well, it's the right behavior. When you set an absolute positioned div, it goes out of the "normal" flow. Maybe you could use a "position:relative" and change the way you position your div, or use javascript.