Having trouble centering a DIV horizontally inside another DIV that contains an image? It can be tricky, especially when the image is added into the mix.
I've attempted various methods, but my goal is to have box2 centered at the bottom of the parent DIV, on top of the image, regardless of its size.
You can take a look at an example image here:
Any suggestions or advice on how to achieve this?
For reference, here is the CSS and HTML code I've been working with:
#box1{
position:relative;
display:inline-block;
width: 200px;
height: 200px;
}
#box2{
width:50px;
margin: 0 auto;
background-color: yellow;
}
<div id="box1">
<img src="http://i44.tinypic.com/2j4akqb.jpg"/>
<div id="box2">box</div>
</div>