使用下面的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: "• ";
}

其他回答

这里有一个可能的解决方案:

代码片段:

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); list-style-position:内心; list-style-type:郎; 的 li {border:固体1px;的 <德> <li>asdasd asdasd asdasd asdasd adasdasd adasdadasd adadas dasdadasdasd asd </li> < li > B < / li > < li > C < / li > < li > D < / li > < li > E < / li > < /德>

在updateColumns()中需要if (column >= columns.length)而不是if (column > columns.length)来列出所有元素(例如跳过C),因此:

function updateColumns(){
    column = 0;
    columnItems.each(function(idx, el){
        if (column >= columns.length){
            column = 0;
        }
        console.log(column, el, idx);
        $(columns.get(column)).append(el);
        column += 1;
    });
}

http://jsfiddle.net/e2vH9/1/

与引导……这个答案(https://stackoverflow.com/a/23005046/1128742)让我想到了这个解决方案:

<ul class="list-unstyled row">
   <li class="col-xs-6">Item 1</li>
   <li class="col-xs-6">Item 2</li>
   <li class="col-xs-6">Item 3</li>
</ul>

http://jsfiddle.net/patrickbad767/472r0ynf/

假设多列布局可以很好地与居中布局,证明网格布局与水平间隙。

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>