In the following code, I'm trying to vertical/horizontal center the image inside the red block. Note that after the block there is a centered text.
I guess it is simple, but I've tried many solutions (1, 2, 3, 4, 5), it still does not work as expected...
JSFiddle
.parent {
text-align: center;
width: 33%;
float: left;
}
.child {
background-color: red;
height: 150px;
width: 150px;
display: inline-block;
vertical-align: middle;
}
<div class="parent">
<div class="child">
<img src="http://dlg.galileo.usg.edu/images/Historic_Architecture_and_Landscapes.gif" />
</div>
<p>Legend of the block</p>
</div>
<div class="parent">
<div class="child">
<img src="http://dlg.galileo.usg.edu/images/Historic_Architecture_and_Landscapes.gif" />
</div>
<p>Legend of the block</p>
</div>
<div class="parent">
<div class="child">
<img src="http://dlg.galileo.usg.edu/images/Historic_Architecture_and_Landscapes.gif" />
</div>
<p>Legend of the block</p>
</div>
Constraints:
I display several blocks, and the width:33%
and float: left
comes from Bootstrap classes and can not be deleted.