tags:

views:

449

answers:

4

If you paste the following code into a test.html and browse with firefox,it's ok. But if you browse with IE,you can see that there are more space to the right of <a> element.:

<style>
li { 
    display:inline;
    margin:0 90px;
    padding:6px 12px;
    background:#777777 none repeat scroll 0 0;
}



li a {
    color:#FFFFFF;
    text-decoration:none;
    font-weight:bold;
}
</style>


<div id="tabs">
    <div class="nav">
     <ul>
      <li><a href="test">test</a></li>
      <li><a href="test">test</a></li>
      <li><a href="test">test</a></li>
      <li><a href="test">test</a></li>
      <li><a href="test">test</a></li>
     </ul>
    </div>
</div>

EDIT:How to make the text even in IE?

A: 

I did look at your source and tried it for myself.

In Firefox 3.0.11 and Internet Explorer 8 I was showing pretty much identical pages.

One thing I can say is that the pages looked different initially because my browsers were at different widths but not the margin problem you were having. In my case resizing the browser worked.

But the problem you're having is common. Internet Explorer will almost always display pages different than a typically standards-compliant browser will. One way that people have found to work around this (and this may very well solve your problem) is to use a CSS Reset sheet.

Some good ones are:

T Pops
I've tried the css reset sheet,but not working.There are still more space to the right of text than to the left.
Shore
A: 

The problem is an unfortunate disagreement between the browsers as to where the CSS box model decides what to do about the padding:

  • IE decreases the space for the content within a div when you increase the padding, so keeping the div size the same
  • Firefox increases the div size with the padding, keeping the content size the same.
Jeremy Smyth
Any way to achieve the goal,say,make the text centralized?
Shore
A: 

Tested in IE6, it seems to add an extra space to the anchor tags. Copy and Paste it and you will see for yourself. Firefox does not add the extra space.

You can change the margin for IE if you want. Its not a perfect solution, but it may help you to make the tabs look similar. If you need it to be identical in all browsers, you could always use an image instead. But try this:

li a {
color:#FFFFFF;
text-decoration:none;
font-weight:bold;
}

*html li a {
color:#FFFFFF;
text-decoration:none;
font-weight:bold;
margin-right:-3px;
}

*+html li a {
color:#FFFFFF;
text-decoration:none;
font-weight:bold;
margin-right:-3px;
}
Jon
But if you look at the 6 tabs of stackoverflow.com,you can see it's centered both in IE and firefox,without using that hack,right?
Shore
stackoverflow is using float:left on the li instead of display:inline. I really recommend you get the firebug plugin for firefox. It makes debugging and looking at how other websites write their code much easier.
Emily
A: 

To answer your question simply: put all your li elements on a single line or float them, IE has some issues with white-space and lists.

Richard M
I can't believe it,but after I put all UL and LIs on a single line,it works!
Shore
This bug will go when using float?
Shore