How to spread list to columns?

Discussion in 'HTML & Website Design' started by Allardyce, Apr 12, 2009.

  1. #1
    Hello All,

    I have some list in HTML format:

    <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
    <li>Item5</li>
    </ul>

    It looks now so:

    Item1
    Item2
    Item3
    Item4
    Item5

    It forms automatically from ASP.NET.
    I wuld like automatically divide it into 2 parts so that it should looks like this:

    Item1 Item2
    Item3 Item4
    Item5

    Also it must be bulleted.

    How to do it?

    Thank you.

    Serge.
     
    Allardyce, Apr 12, 2009 IP
  2. johnrobert

    johnrobert Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,
    hey it can be easily done in css.Is it possible to use css ,so use it.
     
    johnrobert, Apr 12, 2009 IP
  3. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #3
    Set a class, say .special, on the first item and every other item thereafter. Style the item like so:
    
    .special {
      float: left;
      clear: left;
      width: 50%;
      }
    Code (markup):
    With the html like this:
    <ul>
      <li class="special">Item1</li>
      <li>Item2</li>
      <li class="special">Item3</li>
      <li>Item4</li>
      <li class="special">Item5</li>
    </ul>
    Code (markup):
    Set ul {overflow:hidden;} to enclose the last unpaired float, if any.

    cheers,

    gary
     
    kk5st, Apr 13, 2009 IP
  4. Allardyce

    Allardyce Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    How? Help please.
     
    Allardyce, Apr 13, 2009 IP
  5. Allardyce

    Allardyce Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I can't do it by handle. It must made automatically.
     
    Allardyce, Apr 13, 2009 IP
  6. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #6
    That's what the script does for you.

    When you fill your array from whatever source for the list, as you step through creating the list, add the class token to every other list element. Loosely, using php syntax, 'cuz that's what I know:
    
    // $listitems is the filled array
    
    for ($i = 0; $i < $listitems.length; $i++) {
      if ($i % 2 == 0) {
        echo "<li class="special">$listitems[$i]</li>";
      } else {
        echo "<li>$listitems[$i]</li>";
      }
    Code (markup):
    cheers,

    gary
     
    kk5st, Apr 13, 2009 IP
  7. Allardyce

    Allardyce Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks, Gary.
    Hope it will help me.
    Serge.
     
    Allardyce, Apr 13, 2009 IP