I want to divide the list into multiple column and each column should have maximum number of 5 data list same as shown in below image. Please guide how can I achieve this?
Asked
Active
Viewed 1.8k times
2
-
1http://jsfiddle.net/k7hk6/ – dersvenhesse Feb 04 '14 at 08:58
-
Do you need to support IE8 and IE9? I don't think this is supported in those browsers. A polyfill for this probably exists though. – Gohn67 Feb 04 '14 at 09:09
4 Answers
6
CSS code:-
#cols {
-moz-column-count: 3;
-moz-column-gap: 20px;
-webkit-column-count: 3;
-webkit-column-gap: 20px;
column-count: 3;
column-gap: 20px;
}
HTML:-
<div id="cols">
<ul>
lists
</ul>
</div>

user2804021
- 151
- 5
4
CSS3 columns should be the optimal choice (update: also flexbox), but unfortunately has not a wide support yet. You can achieve the same result with simple 2d-transforms (available also on IE9
)
See http://jsfiddle.net/79rtx/1/
Basically all list-items are floated, the unordered list is rotated by -90deg. and list-items rotated by 90deg.
Relevant css
div {
border : 1px green solid;
/* use easyclearing on div (or this workaround) */
overflow : auto;
height : auto;
}
/* clear */
ul + * { clear: both; }
ul {
float : left;
height : 160px; /* (30 + 2px) * 5 */
-webkit-transform : rotate(-90deg);
-moz-transform : rotate(-90deg);
-ms-transform : rotate(-90deg);
-o-transform : rotate(-90deg);
transform : rotate(-90deg);
}
li:nth-child(5n+1) { clear: right; }
li {
width : 30px;
height : 30px;
float : right;
margin : 1px;
background : #ccc;
-webkit-transform-origin : 50% 50%;
-moz-transform-origin : 50% 50%;
-ms-transform-origin : 50% 50%;
-o-transform-origin : 50% 50%;
transform-origin : 50% 50%;
-webkit-transform : rotate(90deg);
-moz-transform : rotate(90deg);
-ms-transform : rotate(90deg);
-o-transform : rotate(90deg);
transform : rotate(90deg);
}

Fabrizio Calderan
- 120,726
- 26
- 164
- 177
-
Can you please check http://jsfiddle.net/79rtx/235/ there seems to be issue in your code when number of list item is not dynamic and becomes one . – Prafulla Kumar Sahu Mar 23 '17 at 11:00
2
CSS
ul {
column-count:4;
-moz-column-count:4;
-webkit-column-count:4;
}
HTML
<ul>
<li>list item 1</li>
<li>list item 2</li>
<li>list item 3</li>
<li>list item 4</li>
<li>list item 5</li>
<li>list item 6</li>
<li>list item 7</li>
<li>list item 8</li>
<li>list item 9</li>
<li>list item 10</li>
<li>list item 11</li>
<li>list item 12</li>
<li>list item 13</li>
<li>list item 14</li>
<li>list item 15</li>
<li>list item 16</li>
<li>list item 17</li>
</ul>

Sajad Karuthedath
- 14,987
- 4
- 32
- 49
-
Can you please check the issue with your code when number of list item is dynamic and becomes one http://jsfiddle.net/ZTAM8/94/ – Prafulla Kumar Sahu Mar 23 '17 at 11:02
0
CSS3 has properties to divide your content in columns: http://css-tricks.com/snippets/css/multiple-columns/. To have only five items on each column you can adjust the height of the list container.

Manuel Bécares
- 88
- 10