-2

With the following HTML, what is the easiest method to display the list as two columns? First column must have custom height. Second column will depend on the height of the first

<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
    <li>5</li>
    <li>6</li>
</ul>

Desired display:

1 6
2
3
4
5

or if you reduce height of first column:

1 5
2 6
3
4
ironfist
  • 21
  • 4

1 Answers1

-2

Best way is to filter your ul list :

$('ul').filter(function(){
    return this.childNodes.length > 5
}).addClass('twoColumns');

and add class to separate if number of element superior to your value :

 ul.twoColumns {
      list-style: none;
        columns: 2;
        -webkit-columns: 2;
        -moz-columns: 2;
    }
Léo R.
  • 2,620
  • 1
  • 10
  • 22