如何使用flex分配一行中的元素来维护两个元素
How to use flex to allocate elements in a row to maintain two elements
我希望我的元素在屏幕中间,在手机上垂直排列phone,但是当切换到平板电脑时,我希望呈现的屏幕是两个元素并排,从左到右呈现!
附上原理图,卡住了,不知道怎么实现这样的布局
ul {
display: flex;
flex-direction: column;
align-items: center;
}
@media (min-width: 768px) {
ul {
flex-direction: row;
}
}
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
这是您要找的吗?
ul {
display: flex;
flex-direction: column;
align-items: center;
}
@media (min-width: 768px) {
ul {
flex-direction: row;
flex-wrap:wrap
}
li {
min-width:50%
}
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
你可以尝试这样的事情。本质上只是制作两个不同的 ul
,然后将其嵌套在 wrapper
中。然后你可以告诉浏览器切换到 flex-column
手机。调整浏览器大小看看效果。
ul {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
}
.wrapper {
display: flex;
justify-content: center;
}
/* change to column for phones */
@media only screen and (max-width: 600px) {
.wrapper {
flex-direction: column;
}
}
<div class="wrapper">
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
</div>
我希望我的元素在屏幕中间,在手机上垂直排列phone,但是当切换到平板电脑时,我希望呈现的屏幕是两个元素并排,从左到右呈现!
附上原理图,卡住了,不知道怎么实现这样的布局
ul {
display: flex;
flex-direction: column;
align-items: center;
}
@media (min-width: 768px) {
ul {
flex-direction: row;
}
}
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
这是您要找的吗?
ul {
display: flex;
flex-direction: column;
align-items: center;
}
@media (min-width: 768px) {
ul {
flex-direction: row;
flex-wrap:wrap
}
li {
min-width:50%
}
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
你可以尝试这样的事情。本质上只是制作两个不同的 ul
,然后将其嵌套在 wrapper
中。然后你可以告诉浏览器切换到 flex-column
手机。调整浏览器大小看看效果。
ul {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
}
.wrapper {
display: flex;
justify-content: center;
}
/* change to column for phones */
@media only screen and (max-width: 600px) {
.wrapper {
flex-direction: column;
}
}
<div class="wrapper">
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
<ul>
<li>title</li>
<li>title</li>
<li>title</li>
<li>title</li>
</ul>
</div>