By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,564 Members | 1,081 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,564 IT Pros & Developers. It's quick & easy.

IE bug: floated <LI> in 100% width <UL> wraps to next line

P: n/a
Hi,

Got an unordered list with 100% width, with 5 list items of 20% width
styled to fill the width of the container element.

Renders fine in Mozilla, but when you change the size of the window in
IE, the last item in the list has a nasty tendency to wrap down to the
next line (and stay there).

I can hack it (imperfectly) by setting the width of the list items to
19.9%, but I was wondering whether anyone has a more elegant solution
that they might be kind enough to direct me to?

Thanks in advance.

Example HTML to reproduce:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>CSS test</title>
<style>
body
{
font-size: 80%;
font-family: Tahoma, Verdana;
margin: 0;
padding: 0;
}
#globalnav
{
width: 100%;
margin: 0;
padding: 0;
}
li.globalheading
{
width: 20%;
}
#globalnav li
{
list-style: none;
display: inline;
background: yellow;
height: 20px;
}
#globalnav a
{
text-decoration: none;
display: block;
text-align: center;
}
</style>
</head>
<body>
<ul id="globalnav">
<li class="globalheading">
<a href="http://www.foo.com/">Group</a>
</li>
<li class="globalheading">
<a href="http://www.foo.com/australia/">Australia</a>
</li>
<li class="globalheading">
<a href="http://www.foo.com/asiapacific/">Pacific Asia
Central Europe</a>
</li>
<li class="globalheading">
<a href="http://www.foousa.com/">the Americas</a>
</li>
<li class="globalheading">
<a href="http://www.foo.com/europe/">Europe</a>
</li>
</ul>
</body>
</html>
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Els
Matt wrote:
Hi,
Hello,
Got an unordered list with 100% width, with 5 list items of
20% width styled to fill the width of the container
element.

Renders fine in Mozilla,
Really? I looked at it in Firefox, and it gives a vertical
list, not horizontal.
but when you change the size of
the window in IE, the last item in the list has a nasty
tendency to wrap down to the next line (and stay there).

I can hack it (imperfectly) by setting the width of the
list items to 19.9%, but I was wondering whether anyone has
a more elegant solution that they might be kind enough to
direct me to?
If you only want it to work in IE, then the 19.9% is the way
to go. If you want it to work in more browsers, you have a
problem:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN"> <html>
This doctype without a dtd throws IE in quirksmode, which is
why it does what you want. Try this one to see what I mean:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

[...]
li.globalheading
{
width: 20%;
}
You are giving the li element a width,
#globalnav li
{
display: inline;


and then tell it to be inline.
Inline elements don't "listen" to widths.
So your choice is either: use inline elements and don't let it
fill up the width of the container, or, use block elements and
float them.

With floated li elements you will encounter your initial
problem in IE again, and yes it's a bug, and yes, 19.9% is the
solution :-)

One thought: You said it was working in Mozilla.
Could it be that the code you last tested already had
"display:inline" replaced by "float:left" ?

In that case, this is one of those fine examples why online
examples are better than copy paste code in the message.

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos vo. O resto imperfeito.
- Renato Russo -
Jul 21 '05 #2

P: n/a
On 11 Feb 2005 10:08:31 -0800 Matt wrote:
Hi, Got an unordered list with 100% width, with 5 list items of 20% width
styled to fill the width of the container element. Renders fine in Mozilla, but when you change the size of the window in
IE, the last item in the list has a nasty tendency to wrap down to the
next line (and stay there). I can hack it (imperfectly) by setting the width of the list items to
19.9%, but I was wondering whether anyone has a more elegant solution
that they might be kind enough to direct me to? Thanks in advance.


<li><div>testing 1 2 3</div></li>

Now define the division instead of the "li".

List only has these properties: <li CLASS="" DIR="" ID="" LANG="" STYLE=""
TITLE="" TYPE="" VALUE=""> and all the mouse tricks.

So you can't define something it does not have to begin with.
Jul 21 '05 #3

P: n/a
"Richard" <An*******@127.001> wrote:
On 11 Feb 2005 10:08:31 -0800 Matt wrote:
Got an unordered list with 100% width, with 5 list items of 20% width
styled to fill the width of the container element.
Renders fine in Mozilla, but when you change the size of the window in
IE, the last item in the list has a nasty tendency to wrap down to the
next line (and stay there).

I can hack it (imperfectly) by setting the width of the list items to
19.9%, but I was wondering whether anyone has a more elegant solution
that they might be kind enough to direct me to?


Matt, please do not listen to Richard, he's an idiot and never gives
good advice.
<li><div>testing 1 2 3</div></li>

Now define the division instead of the "li".
What difference do you think that will make?
List only has these properties: <li CLASS="" DIR="" ID="" LANG="" STYLE=""
TITLE="" TYPE="" VALUE=""> and all the mouse tricks.
"all the mouse tricks"? Do you mean cartwheels and handstands?

No, you probably mean the event handlers. There, that's today's new
phrase for you to start parroting back in your garbage posts "event
handlers", say it out loud a few times if that helps you remember it.

But be careful, not all event handlers are mouse related, in fact for
accessibility reasons you're recommended to avoid device specific
events and use logical ones instead.
So you can't define something it does not have to begin with.


What are you blathering about?

This is a stylesheets newsgroup so I think it's fairly safe to assume
that Matt was setting the width via CSS, in which case the class, id
or style attributes would be perfectly capable of handling whatever he
needs.

In fact if he was setting something he wasn't allowed to we would
expect the <li>s to have their default width of 100% in all browsers
which doesn't match the dscribed problem at all.

Please refrain from giving any adviceat all until you have (a) learnt
to read the questions properly and (b) understood the basics of HTML
and CSS.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 21 '05 #4

P: n/a
Hi Els,
With floated li elements you will encounter your initial
problem in IE again, and yes it's a bug, and yes, 19.9% is the
solution :-)
Oh well. I'm using the '* html ...' selector hack to set it to 19.9% in
IE only, so that'll have to suffice I guess.
One thought: You said it was working in Mozilla.
Could it be that the code you last tested already had
"display:inline" replaced by "float:left" ? In that case, this is one of those fine examples why online
examples are better than copy paste code in the message.
Whoops, yes. I am a doofus. Thanks for taking the time to reply anyway.

Matt
Els wrote: Matt wrote:
Hi,


Hello,
Got an unordered list with 100% width, with 5 list items of
20% width styled to fill the width of the container
element.

Renders fine in Mozilla,


Really? I looked at it in Firefox, and it gives a vertical
list, not horizontal.
but when you change the size of
the window in IE, the last item in the list has a nasty
tendency to wrap down to the next line (and stay there).

I can hack it (imperfectly) by setting the width of the
list items to 19.9%, but I was wondering whether anyone has
a more elegant solution that they might be kind enough to
direct me to?


If you only want it to work in IE, then the 19.9% is the way
to go. If you want it to work in more browsers, you have a
problem:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN"> <html>


This doctype without a dtd throws IE in quirksmode, which is
why it does what you want. Try this one to see what I mean:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

[...]
li.globalheading
{
width: 20%;
}


You are giving the li element a width,
#globalnav li
{
display: inline;


and then tell it to be inline.
Inline elements don't "listen" to widths.
So your choice is either: use inline elements and don't let it
fill up the width of the container, or, use block elements and
float them.

With floated li elements you will encounter your initial
problem in IE again, and yes it's a bug, and yes, 19.9% is the
solution :-)

One thought: You said it was working in Mozilla.
Could it be that the code you last tested already had
"display:inline" replaced by "float:left" ?

In that case, this is one of those fine examples why online
examples are better than copy paste code in the message.

--
Els
http://locusmeus.com/
Sonhos vem. Sonhos vo. O resto imperfeito.
- Renato Russo -


Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.