tags:

views:

72

answers:

4

This is OK:

<html>
<head>
<title>tabs</title>
<style>
li { 
    display:inline;
    margin:0 90px;
    background:#777777 none repeat scroll 0 0;
}

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

</head>
<body>
<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>
</body>
</html>

But if I change li a to make it display:block, everything is gone. Why?

<html>
<head>
<title>tabs</title>
<style>
li { 
    display:inline;
    margin:0 90px;
    background:#777777 none repeat scroll 0 0;
}

li a {
    padding:6px 12px;
    color:#FFFFFF;
    text-decoration:none;
    font-weight:bold;
    display:block;
}
</style>

</head>
<body>
<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>
</body>
</html>

EDIT:It seems the padding:6px 12px here not working at all.But moving it into li will make the padding not even(in IE),how?

A: 

Try floating <li> left instead of displaying it inline.

jeroen
Thank you for your reply.But where is everything gone in the 2nd version?So odd.
Shore
I'm not sure, but there is no point in giving an inline element margins so that combination will never work.
jeroen
Ah, it´s not gone really, it is displayed below the li but in white so you won´t see it. Inline elements behave differently compared to block elements.
jeroen
I think this issue is fixed,but I've met another one,see my update:)
Shore
A: 

Change your color in the li a definition. E.g.:

li a {
    padding:6px 12px;
    color:red;
    text-decoration:none;
    font-weight:bold;
    display:block;
}
RedFilter
oh,it seems inline and block conflicts,and block wins at last?
Shore
A: 
li { 

    margin:0 90px;
    background:#777777 none repeat scroll 0 0;
}


li a {
display:block;    
padding:6px 12px;
    color:#FFFFFF;
    text-decoration:none;
    font-weight:bold;
}
Rony
It seems the padding:6px 12px here not working at all,right?But moving it into li will make the padding not even,how?
Shore
+1  A: 

Your code disappears because you have block elements (with line breaks and height and width) inside an inline element (no line breaks and no height or width).

It may help to review the w3 page on the visual formatting model.

Block level elements are formatted visually as blocks -- they have a line break before and after them.

Inline elements do not form new blocks of content. They are within the flow of the parent block level element.

When you have a block element in an inline element, anonymous boxes are created (see section 9.2.1.1 of the page I linked) and each browser handles that situation differently.

Emily