How to display an unordered list in two columns?

2019-01-02 17:11发布

With the following HTML, what is the easiest method to display the list as two columns?

<ul>
    <li>A</li>
    <li>B</li>
    <li>C</li>
    <li>D</li>
    <li>E</li>
</ul>

Desired display:

A B
C D
E

The solution needs to be able work on Internet Explorer.

13条回答
步步皆殇っ
2楼-- · 2019-01-02 18:13

Here's a possible solution:

Snippet:

ul {
  width: 760px;
  margin-bottom: 20px;
  overflow: hidden;
  border-top: 1px solid #ccc;
}
li {
  line-height: 1.5em;
  border-bottom: 1px solid #ccc;
  float: left;
  display: inline;
}
#double li {
  width: 50%;
}
<ul id="double">
  <li>first</li>
  <li>second</li>
  <li>third</li>
  <li>fourth</li>
</ul>

And it is done.
For 3 columns use li width as 33%, for 4 columns use 25% and so on.

查看更多
登录 后发表回答