35

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Dakota
  • 2,915
  • 2
  • 28
  • 25
  • 1. why are you starting your design without a doctype declaration? 2. i'd like to help, but i'm using FF and so get presented with a 'use webkit' message (which also appears to lack a doctype declaration). – HorusKol Oct 10 '10 at 07:28
  • I've opened things up to Firefox as well now and added a doctype to the browser page. I've still got the issue, and can't quote get it figured out. Since there is a known quantity of extra space, I have done a patch for my main site with a negative margin. What I am interested in is how I can fix this issue. it appears to be some sort of quirk in the rendering engines, because there should be no space after the
      element.
    – Dakota Oct 15 '10 at 23:08

8 Answers8

45

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.

Garland Pope
  • 3,242
  • 1
  • 25
  • 19
eamo
  • 451
  • 1
  • 4
  • 2
  • 3
    This is the actual answer, much better then the "go read about the box model" answer at +8 :) – Chad Okere Dec 28 '10 at 08:15
  • This would be the answer, but *there are no images here*. So, unless this same sillyness can get applied to `
  • `s, it's something else at work.
  • – Dakota Aug 23 '11 at 05:43
  • Note that I set `line-height: 0;` to the _parent_ div element rather than the image inside. I had tried `#parent img { line-height: 0; }` and that did _not_ work. `#parent { line-height: 0; }` was the solution! – Yes Barry Mar 25 '14 at 17:12