In all the following test cases a list (ol
, blue background, black border) contains some list items (li
, red background) each containing a block link (a
display:block, gray background, green on hover.) Depending on several factors IE7-/Win add extra vertical space.
The ‘big’ extra space (B, about the height of a line), case 1, occurs only in IE6-, it has been fixed in IE7. Not so the ‘small’ ones which depend on line-height and vertical-align and occur in various combinations. Only in IE8 the problem is fully fixed.
Description of the test cases:
li
s (sY)a
s have hasLayout (sY aL)li
s have hasLayout (sY lL)li
s and list have hasLayout (sY lL LL)li
s and a
s have hasLayout (sY aL lL)li
s, after the content, before </a> (s2)li
sa
s have hasLayout (aL)li
s, a
s, list have hasLayout (aL lL LL)a
s are relative (aR)a
s have hasLayout, li
s are inline (sY aL lI)li
s have hasLayout and vertical-align:top (sY lL vV)li
s, a
s have hasLayout, li
s have vertical-align:top (aL lL LL vV)1: no hasLayout, white space
2: a
s have hasLayout
3: li
s have hasLayout
4: li
s and list have hasLayout
5: li
s and a
s have hasLayout
6: blanks inside li
s (after content, before </a>)
7: NO white space (neither between nor inside li
s)
8: NO white space; a
s have hasLayout
9: NO white space; li
s, a
s, list have hasLayout
10: NO white space; a
s are relative
11: a
s have hasLayout, li
s are inline
12: li
s have hasLayout and vertical-align:top
13: NO white space; list, li
s, a
s have hasLayout, li
s, a
s have vertical-align:top
Of course the above cases do not exhaust all possible combinations, however they show that hasLayout on the various elements usually creates extra vertical space (and further problems, especially on the list markers: lists, hasLayout and disappearing list markers, problems with lists and hasLayout.) A single fix for the extra space working in all cases does not seem to exist. Simplifying a bit three types of extra space can be distinguished:
li
s. This is triggered by the simple presence of the block a
s, is sensitive to white-space, and disappears giving hasLayout to the a
s. This has been fixed in IE7.li
s. This is triggered by hasLayout on the li
s and is sensitive to vertical-align applied to them. Here the value top has been used to make it to disappear, but bottom and middle could also be useful. It looks like the li
s acted as inline-blocks positioned by default on some baseline. hasLayout on the list has some effect on this space, but does not make it to disappear. hasLayout on the a
s makes it to disappear.li
s or on the a
s. It interferes with the previous one, it is sometimes inside and sometimes outside the li
s (depending on hasLayout on the li
s? hasLayout=outside=blue, no hasLayout=inside=red.) It seems related to the fact that in IE sometimes elements have a sort of minimum height (equal to the normal line-height for the font in use.) Changing vertical-align on the li
s or the a
s makes it to move but not to disappear. This is rather difficult to fix. Giving display:inline to the li
s seems useful. Other tests of these conditions: lists with small line-heights, small line-heights, vertical-align, blocks.
eXtra vertical space: B ~ 1em, S = small, s = small, only with small line-heights, - = no) [IE7 never has B space]
Hover (T = on text, - = full width) [IE7 always full width]
Markers (N = broken, - = ok)
s a l v L | X | H | M | h | |
---|---|---|---|---|---|
1 | Y - - - - | B | T | - | |
2 | Y L - - - | s | - | - | |
3 | Y - L - - | S | T | N | |
4 | Y - L - L | S | T | N | |
5 | Y L L - - | s | - | N | |
6 | 2 - - - - | - | T | - | |
7 | - - - - - | - | T | - | |
8 | - L - - - | s | - | - | |
9 | - L L - L | s | - | N | |
10 | - R - - - | - | ~ | - | |
11 | Y L I - - | - | - | N | |
12 | Y - L V - | s | T | N | |
13 | - L L V L | s | - | N |
Further notes:
a
s helps when these have hasLayout and the li
s do not.li
s, useful to remove the small extra space when they have hasLayout, has an adverse effect on the vertical position of the markers.li
s causes always problems with the markers (though different among IE 5, 5.5, 6, 7.)a
s causes smaller problems with the markers (when a li
wraps on more lines, the marker is positioned ‘low’.)a
s is usually necessary in IE6- if the whole a
s area needs to be clickable/hoverable. position:relative on a
s gives the same effect in cases with small line-heights and does not introduce the extra space (s.) But with big line-heights it makes the a
s not to fill whole area, see IE7-/Win position relative and line-height.“the UL element inherits its line-height from the height of the font attribute for the BODY”. See some specific test cases: IE7-/Win font-size and extra space in lists.
This same page, with line-height: small (1), big (2), or with: unordered lists. To test other combinations use the form below.