I have some markup like so:
<div class="account-picture">
<img src="http://i.imgur.com/Mcr3l.png">
</div>
The div
needs to be floated left. The image is 128px x 128px.
And some css:
.account-picture{
float: left;
background: #FFFFFF;
padding: 10px;
border: 1px solid red;
font-size: 1px;
overflow: hidden;
}
img{
border: 1px solid #F8F8F8;
overflow: hidden;
}
But the problem is there seems to be some extra height assigned to the div. The layout diagrams from firebug are as follows:
Why is the height of the div getting 2 extra pixels? Why does it vary across browsers?
And here's a fiddle: http://jsfiddle.net/mWe5Y/
Why is this happening, and how do I get rid of that extra "height"?
It is mostly used with textarea and div elements. To disable resizable property of an element use resize to none.
You can adjust the vertical-align of the image to position it elsewhere. However, adjusting the vertical-align: top did not completely solve the problem since there was still extra height. In my case, it was necessary to set line-height:0 to completely remove all extra height.
Overflow happens when there is too much content to fit in a box. CSS provides various tools to manage overflow. As you go further with CSS layout and writing CSS, you will encounter more overflow situations.
Because img is an inline element.
To get rid of that extra height:
.account-picture img {
display: block;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With