2

I'd like to create a list on more columns. The number of the columns should change by the size of the window. I can archive this just setting the col-- classes, like this:

<ol>
    <li class="col-md-3 col-sm-4" data-ng-repeat="searchBoxItem in destinations">
        {{searchBoxItem.name}}
    <li>
</ol>

(angularjs is used just to repeat the elemnts, and to explain that they may change in quantity)

The result is quite fine:

enter image description here

when I'm on a pad, it is like this:

enter image description here

The point is that the sorting of the elements increases horizontally. I'd like instead to have them vertically sorted.

I can't imagine a way to do it in CSS3, or even with a clean solution, without involving js.

Possibly, I'd like to have ie8 compatibility :)

Paolo Sanchi
  • 783
  • 9
  • 19

1 Answers1

3

You're going to want to use the CSS3 Multi-Column Layout, via a combination of column-count and column-width. To make this work (and since columns are variable, depending on the device width), you're going to want to add additional classes to your list, to define column states for desktop and mobile.

This will ensure that things are sorted vertically, in a similar way that page columns are defined for print layouts (for example, newspapers).

This guide on CSS Tricks has a great overview of responsive CSS columns.

For example, in your case, you could use something like:

ol li {
  -webkit-columns: 4 100px;
     -moz-columns: 4 100px;
          columns: 4 100px;
}

This basically says, "I want a maximum of 4 columns, with minimum widths of 100px. If the widths get too narrow during scaling...reduce the column count." But I'd recommend adding a class or ID to this area, so that you can target it specifically.

rnevius
  • 26,578
  • 10
  • 58
  • 86
  • Thanks, I forgot, I would need ie8 compatibility :( – Paolo Sanchi Nov 12 '14 at 09:18
  • You should edit your question, so other people don't waste their time with solutions that won't fit the bill. – rnevius Nov 12 '14 at 09:20
  • also see: http://stackoverflow.com/questions/5348061/how-to-display-css3-columns-on-ie – Bass Jobsen Nov 12 '14 at 09:35
  • It works! But the property 'columns' must to be applied to the container, ol, not the single elements. I found the columnizer JQuery plug in the link proposed by Bass Jobsen. I didn't tested it, but it should fix the compatibility propblem whit ie9< http://welcome.totheinter.net/columnizer-jquery-plugin/ https://github.com/adamwulf/Columnizer-jQuery-Plugin – Paolo Sanchi Nov 13 '14 at 15:24
  • here is a JSFiddle: http://jsfiddle.net/xk7ocx6z/ I can't explain why it loses the standard numbers of the
      – Paolo Sanchi Nov 13 '14 at 15:32
    1. I'm not understanding what's wrong with what you linked to. Also, my original answer said to apply the `columns` to `ol li` rather than the `ol` because your question only placed logic within a `li`. My misunderstanding I suppose. – rnevius Nov 13 '14 at 15:51
    2. Throw a `list-style-position: inside;` on it, and you don't have to manually number. – rnevius Nov 13 '14 at 15:56
    3. Note that multi column CSS is not supported by IE8 and IE9, but it is supported by IE10. Here more details: http://caniuse.com/#feat=multicolumn – bart Jun 30 '15 at 03:46