html - 如何让 Flexbox 响应?

标签 html css flexbox responsive

我正在尝试制作响应式布局,但出于某种原因,flexbox 仅在桌面上运行良好。这是我的 HTML 和 CSS:

#wrapper {
   width: 960px;
   margin: auto;
}

.products {
   width: 960px;
   margin-top: 80px;
   margin-bottom: 80px;
   display: flex;
   justify-content: space-between;
}

.product-item {
   width: 300px;
}
<section id="wrapper">
    <article class="products">
	<div class="product-item">
	    <p>FLOWER arrangements</p>
	</div>
	<div class="product-item">
	    <p>FLOWER bouquets</p>
	</div>
	<div class="product-item">
	    <p>FLOWER baskets</p>
	</div>
    </article>
</section>

任何人都可以阐明如何使其具有响应性吗?

最佳答案

问题是您应用到包装器和 flex 容器的硬宽度,这使得它在小屏幕上太宽了。在包装器上设置一个 max-width 以使其灵活:

#wrapper {
  margin: auto;
  max-width:960px;
}

.products {
  display: flex;
  justify-content: space-between;
  margin-top: 80px;
  margin-bottom: 80px;
}

.product-item {
  background-color: gray;
}
<section id="wrapper">
  <article class="products">
    <div class="product-item">
      <p>FLOWER arrangements</p>
    </div>

    <div class="product-item">
      <p>FLOWER bouquets</p>
    </div>

    <div class="product-item">
      <p>FLOWER baskets</p>
    </div>
  </article>
</section>

关于html - 如何让 Flexbox 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53313492/

相关文章:

html - HTML/CSS 中的按钮(列表)溢出

android - WebView 不适用于本地 HTML 文件

javascript - 为什么在我使用 "=="时日期选择器突出显示不起作用?

html - 我想分开 html 和 css 但出了点问题

html - 将宽度悬停在灵活高度的内容框上

css - 为什么对齐: center in the parent mess up my position: absolute overlays?

javascript - 如何防止 2 个 js 文件在我的 HTML 代码中被覆盖?

javascript - 获取多个单选值

javascript - 在 Chrome 和 Firefox 中显示图像

css - flexbox 创建对齐中心内部元素失败