I'm trying to build my first responsive layout. I want to display list items in a vertical line, depending on width.
<div style="height:800px;">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
</div>
1 5 2 6 3 7 4
If the browser gets resized, I want it to become
1 4 7 2 5 3 6
Can someone help me? I've been trying for hours and I can't get anything. I've tried using tables but I can't do it like that either.
This question is related to
css
list
listview
vertical-alignment
Use column-width property of css like below
<ul style="column-width:135px">
Thank you for this example, SPRBRN. It helped me. And I can suggest the mixin, which I've used based on the code given above:
//multi-column-list( fixed columns width)
@mixin multi-column-list($column-width, $column-rule-style) {
-webkit-column-width: $column-width;
-moz-column-width: $column-width;
-o-column-width: $column-width;
-ms-column-width: $column-width;
column-width: $column-width;
-webkit-column-rule-style: $column-rule-style;
-moz-column-rule-style: $column-rule-style;
-o-column-rule-style: $column-rule-style;
-ms-column-rule-style: $column-rule-style;
column-rule-style: $column-rule-style;
}
Using:
@include multi-column-list(250px, solid);
CSS:
#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>
<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 10</li>
<li>List item 11</li>
<li>List item 12</li>
</ul>
</div>
Check demo : https://codepen.io/pen/
You can use flex as below:
.parent-container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
max-height: 100px;
}
Adjust max-height property as per need to generate another columns
Create a list with as many list elements as you want. Then enclose the list in a div, setting style=column-width and style=column-gap, to match the information in your list elements. Do not set style=columns. Totally responsive list that adapts to screen size. No plugins required.
You can do that using CSS3.
Here is the HTML code snippet:
<ul id="listitem_ascolun">_x000D_
<li>1</li>_x000D_
<li>2</li>_x000D_
<li>3</li>_x000D_
<li>4</li> _x000D_
<li>5</li>_x000D_
<li>6</li>_x000D_
<li>7</li>_x000D_
<li>8</li>_x000D_
<li>9</li>_x000D_
<li>10</li>_x000D_
<li>11</li>_x000D_
<li>12</li> _x000D_
</ul>
_x000D_
& Here is the CSS3 code snippet :
#listitem_ascolun ul{margin:0;padding:0;list-style:none;}_x000D_
_x000D_
#listitem_ascolun {_x000D_
height: 500px; _x000D_
column-count: 4;_x000D_
-webkit-column-count: 4;_x000D_
-moz-column-count: 4;_x000D_
}_x000D_
_x000D_
#listitem_ascolun li {_x000D_
display: inline-block;_x000D_
}
_x000D_
If you take a look at the following example - it uses fixed width columns, and I think this is the behavior requested.
http://www.vanderlee.com/martijn/demo/column/
If the bottom example is the same as the top, you don't need the jquery column plugin.
ul{margin:0; padding:0;}_x000D_
_x000D_
#native {_x000D_
-webkit-column-width: 150px;_x000D_
-moz-column-width: 150px;_x000D_
-o-column-width: 150px;_x000D_
-ms-column-width: 150px;_x000D_
column-width: 150px;_x000D_
_x000D_
-webkit-column-rule-style: solid;_x000D_
-moz-column-rule-style: solid;_x000D_
-o-column-rule-style: solid;_x000D_
-ms-column-rule-style: solid;_x000D_
column-rule-style: solid;_x000D_
}
_x000D_
<div id="native">_x000D_
<ul>_x000D_
<li>1</li>_x000D_
<li>2</li>_x000D_
<li>3</li>_x000D_
<li>4</li>_x000D_
<li>5</li>_x000D_
<li>6</li>_x000D_
<li>7</li>_x000D_
<li>8</li>_x000D_
<li>9</li>_x000D_
<li>10</li>_x000D_
<li>11</li>_x000D_
<li>12</li>_x000D_
<li>13</li>_x000D_
<li>14</li>_x000D_
<li>15</li>_x000D_
<li>16</li>_x000D_
<li>17</li>_x000D_
<li>18</li>_x000D_
<li>19</li>_x000D_
</ul>_x000D_
</div>
_x000D_
Source: Stackoverflow.com