If a link with display: block and no explicit dimensions is inside a list item, any spaces or linebreaks that follow the list item in the code will cause extra whitespace to appear in the browser.
Apply zoom: 1 to the block-level links in a conditional comment, or specify display: inline-block followed by display: block for the links.
In some cases IE will treat whitespace (hard returns in your HTML's text) between an ending </li> and the next opening <li> tag as literal linefeeds- adding unwanted whitespace in the rendered HTML page between your list items. Although an easy workaround is to remove all space between closing and the next subsequent opening <li> tags, it isn't optimal for code readability.
There are two ways to fix this bug: The first is the IE7-safe replacement for the Holly Hack; it involves specifying zoom: 1 for the links inside a conditional comment.
<!--[if IE]>
<style type="text/css">
a { zoom: 1;}
</style>
<![endif]-->
The second fix involves a cascading 'juggle' of the inline-block property on listed anchors to turn on hasLayout, then revert the rule without turning hasLayout back off. For example:
a { display: inline-block; }
a { display: block; }
The first rule turns on hasLayout in IE, while the second rule will override the first for all intents and purposes- without turning off hasLayout. Nice workaround, Gary!
Bug and fix originally published by Gary Turner at CSS Creator.com.
Text ID: EXTRA_WHITESPACE_IN_LIST_LINKS
To add a comment, please Log in.
Some Help
by MAE6093 on June 1, 2009
New to all of this, I tried adding this to my page, and Adobe still says i have the white space problem. If anybody can point tell me how to add the necessary hack/filter info to a page...I would appreciate it.
Thanks
by julzmon on February 3, 2009
All of these work well... Thank you!
Can't take all the credit, wish I could :)
by gary.turner on February 3, 2009
I believe I was among the early reporters of this bug, but to my knowledge, Clair Campbell, http://www.tanfa.co.uk/archives/show.asp?var=300 should get credit for the elegant "tripswitch" hack.
cheers
Try This One
by BadexBinliner on November 12, 2008
li {
height: 1em;
}
html>body li {
height: auto;
}
Can't be group in the same rule
by Thierry Koblentz on December 17, 2006
I'm answering my own question here :)
IE does not turn on "hasLayout" if both declarations are in the same rule.
Heads-up about removing whitespace
by Thierry Koblentz on December 17, 2006
"an easy workaround is to remove all space..."
Removing whitespace is an easy fix, but it may create issues:
http://www.tjkdesign.com/adobe_cssadvisor/whitespace_between_elements/
Best workaround ever
by Thierry Koblentz on December 17, 2006
I didn't know about that one. Very smart.
But is there a reason for using two rules instead of one? Like this:
a { display: inline-block;display: block; }