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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matt

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

    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.globalheadin g
    {
    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="globalhe ading">
    <a href="http://www.foo.com/">Group</a>
    </li>
    <li class="globalhe ading">
    <a href="http://www.foo.com/australia/">Australia </a>
    </li>
    <li class="globalhe ading">
    <a href="http://www.foo.com/asiapacific/">Pacific Asia
    Central Europe</a>
    </li>
    <li class="globalhe ading">
    <a href="http://www.foousa.com/">the Americas</a>
    </li>
    <li class="globalhe ading">
    <a href="http://www.foo.com/europe/">Europe</a>
    </li>
    </ul>
    </body>
    </html>
  • Els

    #2
    Re: IE bug: floated &lt;LI&gt; in 100% width &lt;UL&gt; wraps to next line

    Matt wrote:
    [color=blue]
    > Hi,[/color]

    Hello,
    [color=blue]
    > 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,[/color]

    Really? I looked at it in Firefox, and it gives a vertical
    list, not horizontal.
    [color=blue]
    > 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?[/color]

    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:
    [color=blue]
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
    > Transitional//EN"> <html>[/color]

    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">

    [...]
    [color=blue]
    > li.globalheadin g
    > {
    > width: 20%;
    > }[/color]

    You are giving the li element a width,
    [color=blue]
    > #globalnav li
    > {
    > display: inline;[/color]

    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
    Blog and other pages, mostly outdated.

    Sonhos vem. Sonhos vão. O resto é imperfeito.
    - Renato Russo -

    Comment

    • Richard

      #3
      Re: IE bug: floated &lt;LI&gt; in 100% width &lt;UL&gt; wraps to next line

      On 11 Feb 2005 10:08:31 -0800 Matt wrote:
      [color=blue]
      > Hi,[/color]
      [color=blue]
      > Got an unordered list with 100% width, with 5 list items of 20% width
      > styled to fill the width of the container element.[/color]
      [color=blue]
      > 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).[/color]
      [color=blue]
      > 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?[/color]
      [color=blue]
      > Thanks in advance.[/color]

      <li><div>testin g 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.


      Comment

      • Steve Pugh

        #4
        Re: IE bug: floated &lt;LI&gt; in 100% width &lt;UL&gt; wraps to next line

        "Richard" <Anonymous@127. 001> wrote:[color=blue]
        >On 11 Feb 2005 10:08:31 -0800 Matt wrote:
        >[color=green]
        >> Got an unordered list with 100% width, with 5 list items of 20% width
        >> styled to fill the width of the container element.[/color]
        >[color=green]
        >> 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).[/color]
        >[color=green]
        >> 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?[/color][/color]

        Matt, please do not listen to Richard, he's an idiot and never gives
        good advice.
        [color=blue]
        ><li><div>testi ng 1 2 3</div></li>
        >
        >Now define the division instead of the "li".[/color]

        What difference do you think that will make?
        [color=blue]
        >List only has these properties: <li CLASS="" DIR="" ID="" LANG="" STYLE=""
        >TITLE="" TYPE="" VALUE=""> and all the mouse tricks.[/color]

        "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.
        [color=blue]
        >So you can't define something it does not have to begin with.[/color]

        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 <steve@pugh.net > <http://steve.pugh.net/>

        Comment

        • mattoc@tiscali.co.uk

          #5
          Re: IE bug: floated &lt;LI&gt; in 100% width &lt;UL&gt; wraps to next line

          Hi Els,
          [color=blue]
          > 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 :-)[/color]

          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.
          [color=blue]
          > 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 " ?[/color]
          [color=blue]
          > In that case, this is one of those fine examples why online
          > examples are better than copy paste code in the message.[/color]

          Whoops, yes. I am a doofus. Thanks for taking the time to reply anyway.

          Matt


          Els wrote:[color=blue]
          > Matt wrote:
          >[color=green]
          > > Hi,[/color]
          >
          > Hello,
          >[color=green]
          > > 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,[/color]
          >
          > Really? I looked at it in Firefox, and it gives a vertical
          > list, not horizontal.
          >[color=green]
          > > 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?[/color]
          >
          > 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:
          >[color=green]
          > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
          > > Transitional//EN"> <html>[/color]
          >
          > 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">
          >
          > [...]
          >[color=green]
          > > li.globalheadin g
          > > {
          > > width: 20%;
          > > }[/color]
          >
          > You are giving the li element a width,
          >[color=green]
          > > #globalnav li
          > > {
          > > display: inline;[/color]
          >
          > 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 vão. O resto é imperfeito.
          > - Renato Russo -[/color]

          Comment

          Working...