[英]how to arrange the list items using column count?
i want to arrange the list items using column count or any other alternative. 我想使用列数或其他任何方式排列列表项。 i want to limit the rows in this code
<li>
may vary 我想限制此代码中的行
<li>
可能有所不同
<ul>
<li>a</li>
<li>b</li>
<li>c</li>
<li>d</li>
<li>e</li>
<li>f</li>
<li>1</li>
<li>2</li>
<li>g</li>
<li>h</li>
<li>i</li>
<li>j</li>
<li>k</li>
</ul>
and css is 和CSS是
ul {
column-count: 3;
column-gap: 20px;
}
Desired output 所需的输出
a g
b h
c i
d j
e k
f
1
2
my two-pennies: example in js 我的两个便士: js中的示例
just using some jquery to move items in an intermediate div with float: left
只是使用一些jquery在带有
float: left
的中间div中移动项目float: left
You can do it like this (which won't give you the one-and-a-half columns you have, though...): 您可以像这样进行操作(尽管这样不会给您提供一个半栏的内容……):
ul {
width: 50%;
-webkit-column-count: 3;
-moz-column-count: 3;
column-count: 3;
-webkit-column-gap: 20px;
-moz-column-gap: 20px;
column-gap: 20px;
}
li {
list-style: none;
background: #ddd;
}
As you wrote, the content will always be distributed as evenly as possible in the columns. 如您所写,内容将始终在各列中尽可能均匀地分布。 A height setting will only influence the result if it's smaller than what fits into the number of given columns.
高度设置只有在小于给定列数的范围内才会影响结果。 See this codepen:
看到这个codepen:
http://codepen.io/anon/pen/pbVgxb http://codepen.io/anon/pen/pbVgxb
Try this. 尝试这个。
.ulist { -moz-column-count:2; -webkit-column-count:2; column-count:2; height: 200px; } li { height:20px; }
<ul class="ulist"> <li>a</li> <li>b</li> <li>c</li> <li>d</li> <li>e</li> <li>f</li> <li>1</li> <li>2</li> <li>g</li> <li>h</li> <li>i</li> <li>j</li> <li>k</li> </ul>
You could use flex-direction: column
and flex-wrap: wrap
to make the first column fill first, then the second, ... etc: 您可以使用
flex-direction: column
和flex-wrap: wrap
来使第一列首先填充,然后填充第二列,等等。
ul { display: flex; flex-direction: column; flex-wrap: wrap; height: 190px; width: 300px; border: 1px solid; }
<ul> <li>a</li> <li>b</li> <li>c</li> <li>d</li> <li>e</li> <li>f</li> <li>1</li> <li>2</li> <li>g</li> <li>h</li> <li>i</li> <li>j</li> <li>k</li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.