Accessibility

CSS Advisor

Extra Whitespace in List Links bug

by CSSAdvisorAdmin on November 1, 2006
Edited by: LoriHC (Dreamweaver Team) on July 28, 2011
Avg Rating 4.1 (19)   |   Log in to rate post.

Tagged with Explorer 6.0 , Explorer 5.0 , display , Explorer 5.5

Problem

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.

Solution

Apply zoom: 1 to the block-level links in a conditional comment, or specify display: inline-block followed by display: block for the links.

Detailed description

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



Comments (9)

To add a comment, please Log in.




I use it and work perfect

It's work perfect with minor change to work with my site
first put that code on the  header under your main style (if you use it in the same html file )
second use your element ID or class that have the issue "don't use it to all <a> element"  by changing the code like this
<!--[if IE]>
<style type="text/css">
#LeftBar ul li a { zoom: 1;}
</style>
<![endif]-->
as you see    #LeftBar ul li a      is my specify element that  had the problem ...
that  element used for list that viewing  vertically ...not working with horizontal(in-line) list ..
I use the second solution
a { display: inline-block; }
ant it work perfect too .
Have nice day

Placement

I'm an old html'er and have been using a bunch of new tools - Dreamweaver, Fireworks, and I'm learning CSS and Javascript all at the same time.  So forgive my ignorance but where do I put the second option?  Does this go on my CSS form or in the body of my html...if so, does it go within the UL tags?  I'm lost...but am a fast learner.  ;)

Thanks!

Some Help

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

All of these work well... Thank you!

Can't take all the credit, wish I could :)

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

li {
height: 1em;
}
html>body li {
height: auto;
}

Can't be group in the same rule

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

"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

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; }





CSS Advisor home
Submit a post

rss

CSS ADVISOR RSS FEEDS
Recent: POSTS | COMMENTS | EDITS


Browsers
Internet Explorer (98)
Mozilla/Firefox (49)
Opera (17)
Safari (35)
CSS Properties
Background (22)
Border (8)
Color (8)
Float (22)
Font (5)
Margin (10)
Padding (8)
Position (39)
Text (27)
Width/Height (23)