Forum Moderators: not2easy

Message Too Old, No Replies

inline list w/ borders breaks in IE6

         

heisters

11:03 pm on Nov 22, 2006 (gmt 0)

10+ Year Member



Hi all,

I get a weird error with the following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Foo</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<style type="text/css">
ul {
list-style: none;
}
li {
border: 1px solid red;
display: inline;
}
</style>
</head>
<body>
<ul>
<li><a href="#">Foo</a></li>
<li><a href="#">Bar</a></li>
</ul>
</body>
</html>

In FF this renders as I would expect: two boxes next to one another with red borders. In IE, it chops of the top and bottom borders. The problem becomes exacerbated when you try to apply padding to the li elements, in which case IE adds the right and left padding, but chops off everything greater than the line height.

I tried triggering hasLayout with "height: 0;", tried playing with line-height, tried different height values. Finally, the only way I could get it to work was to add enough padding to the ul to give room for the li's padding + border.

I tried changing the doctype, but that didn't seem to change anything. Does anybody have any idea what this bug is? Is there a better way to fix it than adding padding to the ul?

Thanks,
Ian

Maglez2000

3:41 pm on Nov 24, 2006 (gmt 0)

10+ Year Member



Hello.

Try this definition for the li element

li {border: 1px solid red; display:inline-block; float:left}

See the display and float rules.

It may be a better way to solve it. I only test it on IE7.

Good luck.

Miguel Gonzalez.

Maglez2000

3:48 pm on Nov 24, 2006 (gmt 0)

10+ Year Member



Actually, you don't need 'inline-block', just 'block'.

Miguel Gonzalez.

snair

1:52 am on Nov 26, 2006 (gmt 0)

10+ Year Member



I think IE has problems with display:inline. That's why using float would be better. something like

li {
border: 1px solid red;
float: left;
margin-right: 10px;
}

seems to work in both IE and firefox.

heisters

8:20 pm on Nov 30, 2006 (gmt 0)

10+ Year Member



sorry it took me so long to get back to this.

Interesting: it works, but then FF and IE disagree on the positioning of the list items.

I can't see in the w3.org specs why this works. Nonetheless, I think I kinda prefer setting the padding different for IE, so that it's semantically clear what's going on, rather than floating an element that really doesn't need to float.

Thanks!

Maglez2000

3:12 pm on Dec 1, 2006 (gmt 0)

10+ Year Member



Yes, there are lot of disagreement with the W3C recommendations, as you see, those are recommendations.

This may helps, W3C - CSS - 10.6 Computing heights and margins [w3.org]

You actually don't need to make those div to float, you could do...

<ul style="border:1px solid white">

If your background is white.

To see what's going on, run the following code on IE and FF.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
<style type="text/css">
div{border:1px solid aqua}
ul{display:inline}
li{border:1px solid lime;display:inline;width:10px;padding:4px}
</style>
</head>
<body>
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>

Have a look at how those li elements overflow the div element.

The different between IE and FF is the way they compute the height. As the CSS recommendation says, to compute an element height it depends of if it is a inline, block, float...... and also the way IE and FF count where a block starts, at the margin, at the border, at the padding......

Anyway, this is part of the CSS and browsers fun, I hope you enjoy it.

heisters

9:45 pm on Dec 1, 2006 (gmt 0)

10+ Year Member



interesting. Your illustration really cleared up what's going on, thanks.