使用下面的HTML,将列表显示为两列的最简单方法是什么?
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>
想要显示:
A B
C D
E
解决方案需要与Internet Explorer兼容。
使用下面的HTML,将列表显示为两列的最简单方法是什么?
<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>
想要显示:
A B
C D
E
解决方案需要与Internet Explorer兼容。
当前回答
我喜欢现代浏览器的解决方案,但缺少子弹,所以我添加了一个小技巧:
http://jsfiddle.net/HP85j/419/
ul {
list-style-type: none;
columns: 2;
-webkit-columns: 2;
-moz-columns: 2;
}
li:before {
content: "• ";
}
其他回答
这可以使用父div上的column-count css属性来实现,
like
column-count:2;
查看更多细节。
如何使浮动DIV列表出现在列,而不是行
这里有一个可能的解决方案:
代码片段:
ul { 宽度:760 px; margin-bottom: 20 px; 溢出:隐藏; Border-top: 1px实心#ccc; } 李{ 行高:1.5 em; Border-bottom: 1px实体#ccc; 浮:左; 显示:内联; } #双里{ 宽度:50%; } < ul id = "双" > <李>第一李< / > <李>第二李< / > <李>第三李< / > <李>第四李< / > < / ul >
这就完成了。 对于3列使用里宽为33%,对于4列使用25%,依此类推。
现在的日子,对于预期的结果,显示:网格;是最简单的吗?
申{ 显示屏:网格; 格栅:重复(2,1 fr); 的 <德> < li > A < / li > < li > B < / li > < li > C < / li > < li > D < / li > < li > E < / li > < /德>
你也可以让列在左边收缩,并且可以有不同的宽度:
ul { 显示:网格; Grid-template-columns: repeat(2, auto); justify-content:开始; } 李{ margin-left: 1 em; 边框:1px;/*see me */ } < ul > <李> < /李> <李> B李< / > <李> C 123456李< / > <李> D李< / > <李> E李< / > < / ul >
假设多列布局可以很好地与居中布局,证明网格布局与水平间隙。
p { text-align: justify; } ul { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-around; gap: 0 3em; text-transform: capitalize; } <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.</p> <ul> <li>one</li> <li>two</li> <li>three</li> <li>four</li> <li>five</li> <li>six</li> <li>seven</li> <li>eight</li> <li>nine</li> <li>ten</li> </ul> <p>In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.</p>
这对我来说是一个完美的解决方案,我找了很多年:
http://css-tricks.com/forums/topic/two-column-unordered-list/