如何将堆叠的物品放在移动视口的中心?
这是我的摘录:
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
}
.space-between {
justify-content: space-between;
}
.space-between div {
background: pink;
}
.flex-item {
line-height: 50px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
<div class="flex-container space-between ">
<div class="flex-item">very long text 1</div>
<div class="flex-item">very long text 2</div>
<div class="flex-item">very long text 3</div>
</div>
答案 0 :(得分:1)
对于移动视图,应使用@media-query
。重构HTML和CSS后,这是更新的代码
.flex-container {
padding: 0;
margin: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
@media only screen and (max-width: 768px) {
.flex-container {
justify-content: center;
}
}
.flex-container div {
background: pink;
}
.flex-item {
line-height: 50px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
}
HTML
<div class="flex-container space-between ">
<div class="flex-item">very long text 1</div>
<div class="flex-item">very long text 2</div>
<div class="flex-item">very long text 3</div>
</div>