如何在Flex上居中放置容器?

问题描述 投票:0回答:1

如何居中放置.container,以使小屏幕上的项目保留在原处,.container居中。

我的例子https://codepen.io/zakhar_coder/pen/QWbQxdE?editors=1100

.container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.item {
  width: 370px;
  height: 250px;
  background-color: #333;
  margin: 0 30px 30px 0;
}
<div class="container">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>    
</div>

“这是应该看起来的样子。在图片中,图块本身未居中”>

this option of placing elements is not suitable for me

如何居中放置.container,以便小屏幕上的项目保留下来,.container居中。我的示例https://codepen.io/zakhar_coder/pen/QWbQxdE?editors=1100 .container {display:...

css
1个回答
0
投票

您不需要那么做。给容器加max-width并将其宽度强制为100%。之后,您可以使用margin: 0 auto;将其居中。

© www.soinside.com 2019 - 2024. All rights reserved.