I want to overlay the image. I managed to do this, but the image is expanding from the parent div .
I have a div containing inline-block , since I want it to be "automatic size" and not occupy width: 100% . If you look at the current output, you will see that the image may be within the frame with a black edge.
It only needs to work in Chrome if you encounter problems with multiple browsers.
Thanks in advance!
Live demo
CSS
#body_content { border: solid 1px blue; display: inline-block; padding: 5px; } #body_header { border: solid 1px red; font-size: 25px; padding: 5px; } #body_image { position: absolute; } #body_image_caption { color: white; line-height: 30px; margin-left: 10px; } #body_image_container { background: white; border: solid 1px black; margin-top: 3px; padding: 10px; } #body_image_overlay { background-color: black; bottom: 5px; display: block; height: 30px; opacity: 0.85; position: absolute; width: 100%; }â
HTML:
<div id="body_content"> <div id="body_header"> Heading </div> <div id="body_image_container"> <div id="body_image"> <img src="http://i.imgur.com/s6G8n.jpg" width="200" height="200" /> <div id="body_image_overlay"> <div id="body_image_caption"> Some Text </div> </div> </div> </div> </div>
user887515
source share