Why does the HTML5 DOCTYPE mess with my padding?

Dakota picture Dakota · Jun 9, 2010 · Viewed 15.3k times · Source

I have an html5 page with a navbar. Completely scratch coded. I just recently added a doctype to the item, and now I’m getting extra space under my navbar. If I remove the doctype declaration, it goes back to normal. I have completely reset padding, margins, etc. on everything, and cut it down to the a small amount of code that illustrates the issue.

The page can be seen at http://hackthetruth.org/webdesign/broken

Does anyone know why declaring the doctype is messing with the height of a div?

Answer

eamo picture eamo · Aug 11, 2010

I had the same problem with one of my sites. i found this answer here:

"With an HTML5 doctype, images receive what seems to be the line-height attribute which text normally gets, and thus you get a “margin” underneath them. You can either set them to display:block or line-height:0, although I haven’t tested the latter enough to be sure it’s a good fix."

I applied the line-height:0 to the <div> which contained the navigation images. It did the trick for me.