I have a problem with this simple html:
div {
height: 150px;
background: orange;
line-height: 150px;
}
a {
display: inline-block;
vertical-align: middle;
}
figure {
width: 40px;
height: 40px;
background: red;
margin: 0;
}
img {
width: 100%;
height: 100%;
}
<div>
<a href="#">
<figure>
<img src="http://images.freeimages.com/images/previews/8d4/anemone-1372191.jpg" alt="">
</figure>
</a>
<a href="#">Texto del enlace</a>
</div>
I do not understand that the image (img) does not appear centered inside its container (the figure with a red background) which is correctly centered
If we change the position of the image to absolute then it works fine:
div {
height: 150px;
background: orange;
line-height: 150px;
}
a {
display: inline-block;
vertical-align: middle;
}
figure {
width: 40px;
height: 40px;
background: red;
margin: 0;
position: relative; /* añadiendo esto */
}
img {
width: 100%;
height: 100%;
position: absolute; /* ...y esto */
}
<div>
<a href="#">
<figure>
<img src="http://images.freeimages.com/images/previews/8d4/anemone-1372191.jpg" alt="">
</figure>
</a>
<a href="#">Texto del enlace</a>
</div>
Why is it off center in the first version?