如果不修改HTML或使用某些position: absolute
hackery,是否可以将此列表中的项目6和7并排显示在第6行?
ul {
border: 1px solid gray;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
list-style-type: none;
}
li {
width: 33%;
border: 1px solid #ccc;
text-align: center;
}
<div class="flex-container">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
</div>
答案 0 :(得分:2)
这是一种方法:
flex-direction
切换为row
。wrap
。
ul {
display: flex;
justify-content: center;
flex-wrap: wrap;
list-style-type: none;
border: 1px solid gray;
}
li {
flex: 0 0 66%; /* flex-grow flex-shrink flex-basis */
text-align: center;
border: 1px solid #ccc;
}
li:nth-last-child(-n + 2) {
flex-basis: 45%;
}
<div class="flex-container">
<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 :(得分:1)
你可以这样做:
ul {
border: 1px solid gray;
display: flex;
flex-wrap: wrap;
justify-content: center;
list-style-type: none;
}
li {
min-width: 33%;
max-width: 33%;
border: 1px solid #ccc;
text-align: center;
margin-left: 100%;
margin-right: 100%;
}
li:nth-last-child(-n + 2) {
margin: 0;
}
<div class="flex-container">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
</div>