tags:

views:

102

answers:

5

i have following html page with UL and LI, i try to assign width to each LI but can't see cay success

   <html>
   <head>
   <style type="text/css"> 

   ul
   { 
      overflow-x:hidden;
     white-space:nowrap; 
     height: 1em;
      width: 100%;
     } 

     li
  { 
    display:inline;
     padding-right:10px;
      }       
      </style>
    </head>
    <body>

    <ul> 
        <li style="width:100px">abcdefghijklmonpqrstuvwxyz</li> 
      <li>abcdefghijklmonpqrstuvwxyz</li> 
   <li>abcdefghijklmonpqrstuvwxyz</li> 
   <li>abcdefghijklmonpqrstuvwxyz</li> 
    <li>abcdefghijklmonpqrstuvwxyz</li> 
     <li>abcdefghijklmonpqrstuvwxyz</li> 
      <li>abcdefghijklmonpqrstuvwxyz</li> 
    </ul> 

    </body>
   </html>

because each of my LI has different width.

Thanks

A: 

You are giving the lis display: inline and widthdoesn't apply to inline elements. You'll need to use an alternative to position the elements beside each other such as floating them.

RoToRa
+3  A: 

No, you can't assign width to anything that is displayed inline, which you've set your LI to be. Instead, you most often want to use display: block; float: left; which'll allow for setting width.

David Hedlund
+3  A: 

Try to replace your display:inline by display:inline-block

Gregoire
this will do the trick, unless you're concerned with keeping your code XHTML compliant. inline-block is not supported completely cross browser: http://www.quirksmode.org/css/display.html#t03
Anthony Shaw
+1 This should be the way to do what OP wants. But IE (6 and 7?) will only apply `display: inline-block;` to elements that are naturally inline (`span`, as an example), so one has to be careful with inline-block for pages that are meant to be compatible with *outdated* browsers.
ANeves
A: 

To provide more on the previous two answers, you can't specify the width inline, but you can check out an example on how to do it here

Christin
+1  A: 

Try this CSS

ul {
 white-space: nowrap;
 height: 1em;
 width: 100%;
}

li {
 list-style-type: none;
 width: 100px;
 overflow-x: auto; /* change to hidden if that's what you want */
 float: left;
 margin-right: 10px;
}
fudgey