如何将堆叠的物品放在移动视口的中心?

这是我的片段:



.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>

最佳答案

您应将@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>

关于html - 将Flexbox环绕在移动视口(viewport)上,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52822281/

10-11 11:19