4

Trying to achieve to display the order of my lists in a vertical order.

I have 6 lists, i need to display that the first three should display on the left side and remaining on the right side.

Expected output :

a d
b e
c f

Current Output:

a b
c d
e f

HTML:

<ul>
    <li class="list">
        <a>a</a>
        <ul>
            <li>1</li>
        </ul>
    </li>
    <li class="list">
        <a>b</a>
        <ul>
            <li>2</li>
        </ul>
    </li>
    <li class="list">
        <a>c</a>
        <ul>
            <li>3</li>
        </ul>
    </li>
    <li class="list">
        <a>d</a>
        <ul>
            <li>4</li>
        </ul>
    </li>
    <li class="list">
        <a>e</a>
        <ul>
            <li>5</li>
        </ul>
    </li>
    <li class="list">
        <a>f</a>
        <ul>
            <li>6</li>
        </ul>
    </li>
</ul>

I have attached what I have tried: Demo

And it should support IE8

  • Can you amend them HTML at all, ir is that fixed? – LDJ Sep 11 '15 at 12:50
  • @LDJ : Column-count works, but it is not supporting internet explorer 8 –  Sep 11 '15 at 12:52
  • To support all browsers you should change your html, CSS/JS solutions will most likely have compatibility issues with IE 6/7/8 – Aramil Rey Sep 11 '15 at 12:57
  • @Aramil Rey Can you Please help me out –  Sep 11 '15 at 13:03
  • I don't think the other answers actually get the desired output like you want. When I tried to run the code, I didn't get the expected output like you wanted it. This sounds like a job for Flexbox... So I have a partially working solution so far: http://jsfiddle.net/kgnv2zdw/2/. The HTML change includes adding two list items containing one list each, which displays these two items side-by-side. Is this going in the right direction or did I miss something completely? – UltraSonja Sep 11 '15 at 13:20

4 Answers4

2

Try using

ul {
  column-count: 2;
}
m4n0
  • 29,823
  • 27
  • 76
  • 89
jonazz
  • 41
  • 3
0

Following this answer https://stackoverflow.com/a/24924657/2983435, made some adjustments to your CSS:

ul {
    list-style-type: disc;
    columns: 2;
    -webkit-columns: 2;
    -moz-columns: 2;
    list-style-position: inside;
}
.list{
    border:1px solid red;
}
Community
  • 1
  • 1
Ariel
  • 1,507
  • 2
  • 20
  • 28
0

ul {
   list-style:none;
    -webkit-columns: 2;
   }
.list{
    border:1px solid red;
}

only -webkit-columns: 2; is mostly required for vertical order list items

Neeraj Kumar
  • 3,851
  • 2
  • 19
  • 41
0

Unfortunately, the biggest blocker to any solution given to you (i.e. column and flexbox ) is that you need the solution to be working on IE8. There is no silver bullet when trying to support browsers that old unfortunately.

I've provided some CSS for you to add a flexbox solution for more current browsers (Demo), but you'll need to build in a fallback for IE8 that uses either a display: block or display: table since Flexbox is not supported on IE9 or IE8.

ul {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  height: 150px;
}

li {
  height: 50px;
}

Hope that helps a little bit.

bencodezen
  • 1,023
  • 7
  • 17