css - 努力应对响应式设计

标签 css html flexbox

我正在努力解决一件事。我正在将 psd 编码为 html,但是当我想让我的网站具有响应能力时,我无法用一个 div 解决问题。

https://codepen.io/Dzonyy/pen/jmjOWV

.features_items {
  margin: 0 auto;
  display: flex;
  flex: column;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.features_item {
  padding: 200px 0 100px 0;
  text-align: center;
  position: relative;
}

.features_items h3 {
  padding-top: 80px;
  color: #f4d320;
}

.features_item_text {
  padding-top: 15px;
  line-height: 200%;
}

.features_items_person {
  background: url(../images/person.png) top 20% center no-repeat;
}

.features_items_cloud {
  background: url(../images/cloud.png) top 20% center no-repeat;
}

.features_items_database {
  background: url(../images/database.png) top 20% center no-repeat;
}

.features_items_monitoring {
  background: url(../images/screen.png) top 20% center no-repeat;
}

.features_items_person:before,
.features_items_cloud:before,
.features_items_database:before,
.features_items_monitoring:before {
  content: "";
  position: absolute;
  border-bottom: 2px solid #8d8d99;
  height: 1px;
  width: 15%;
  top: 48%;
  left: 43%;
}
<div class="features_items">
  <figure class="features_item features_items_person">
    <h3>Live Support</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_cloud">
    <h3>Cloud Technology</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_database">
    <h3>Hi Tech Database</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_monitoring">
    <h3>Live Monitoring</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
</div>

总是在同一条车道上? 如何将它们制作成 2 行 2 列,最大宽度 1024px ?

最佳答案

我建议您更改为row方向,然后使元素换行flex-flow: row wrap;

此外,您还为它们指定至少 35% 的宽度 (flex-basis),因此一行中不能容纳超过 2 个。

我更新了这 2 条规则,如下所示,它会在较宽的屏幕上为您提供 2 列,在较小的屏幕上为您提供 1 列。

Updated codepen

堆栈片段

.features_items {
  margin: 0 auto;
  display: flex;
  flex-flow: row wrap;               /*  changed property  */
  justify-content: center;
  align-items: center;
}

.features_item {
  flex-basis: 35%;                   /*  added property  */
  padding: 200px 0 100px 0;
  text-align: center;
  position: relative;
}

.features_items h3 {
  padding-top: 80px;
  color: #f4d320;
}

.features_item_text {
  padding-top: 15px;
  line-height: 200%;
}

.features_items_person {
  background: url(../images/person.png) top 20% center no-repeat;
}

.features_items_cloud {
  background: url(../images/cloud.png) top 20% center no-repeat;
}

.features_items_database {
  background: url(../images/database.png) top 20% center no-repeat;
}

.features_items_monitoring {
  background: url(../images/screen.png) top 20% center no-repeat;
}

.features_items_person:before,
.features_items_cloud:before,
.features_items_database:before,
.features_items_monitoring:before {
  content: "";
  position: absolute;
  border-bottom: 2px solid #8d8d99;
  height: 1px;
  width: 15%;
  top: 48%;
  left: 43%;
}
<div class="features_items">
  <figure class="features_item features_items_person">
    <h3>Live Support</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_cloud">
    <h3>Cloud Technology</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_database">
    <h3>Hi Tech Database</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
  <figure class="features_item features_items_monitoring">
    <h3>Live Monitoring</h3>
    <figcaption class="features_item_text">This is Photoshops version of Lorem Ipsum.Proin gravida nibh vel velit auctor aliquet.</figcaption>
  </figure>
</div>

关于css - 努力应对响应式设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245995/

相关文章:

html - 如何在不增加标题实际高度的情况下增加标题中 Logo 的高度?

javascript - IE 中的选项卡顺序问题与表单中字段的初始 Javascript 选择

javascript - 渲染图像操作 : HTML5 canvas element, 或使用 JS/jQuery 操作 DOM 元素的 CSS 哪个更快?

android - React Native Flat List 调整元素大小

html - 行内垂直居中导航 - 骨架框架

html - 两个导航栏都显示在错误的断点上

javascript - 防止绝对位置元素粘在可滚动 div 内

html - IE7 边框超出容器宽度

html - 带有填充溢出容器的 Flex 元素

html - flex 元素不会进入下一行(不换行)