Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the height of DIVs containing images inflated by 4.5px?

Tags:

html

css

height

This div will have a computed height of 104.5px (in most recent Chrome, FF, and IE)

<div><img src="" height="100px" /></div>

This div will have a computed height of 100px

<div style="overflow:auto;"><img src="" height="100px" style="float:left;" /></div>

I used FireBug to look at the DIVs and IMGs, and both IMGs have 0 for margin, padding, and border, yet the computed height somehow is 4.5px bigger in the first instance.

Why is this? It impacts me when I try to layout a page with a consistent vertical grid. Ideally, I'd like to not have to float the imgs.

I tried to look here ==> http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.7.2 and I even tried vspace=0, but that didn't change anything.

Thanks for your help!

like image 870
Peter Ajtai Avatar asked Oct 18 '25 10:10

Peter Ajtai


2 Answers

clients include their own stylesheets that should be overidden before you try to do any pixel-perfect layouts or cross-browser debugging. Even if you remove all your stylesheets there are still styles on the page.

Try it again with a css reset at the top of your stylesheet. Also, make sure that you're declaring a valid doctype. Use a strict doctype and make sure your code validates if that still doesn't help.

I usually use the meyer web reset with a few minor modifications that suit my workflow.

If other people are seeing 100px then it's likely a client side problem, so hopefully this troubleshoots it for you.

like image 113
David Meister Avatar answered Oct 20 '25 00:10

David Meister


I use Yahoo! CSS Reset to get my browsers all starting from scratch, usually helps.

like image 41
hunter Avatar answered Oct 19 '25 23:10

hunter