弹性物品不能正确包裹和收缩

时间:2019-03-09 06:53:57

标签: html css css3 flexbox alignment

我希望右侧的flex项能够在较小的设备上包裹在图像下方。我还希望两个伸缩项目在收缩时(与浏览器窗口一起)彼此具有相同的高度。

.new-collection-wrapper {
  background-color: #f1f1f1;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.new-collection-card {
  width: 80%;
  margin: 5em 0;
  display: flex;
  align-items: center;
}

.new-collection-card-img img {
  height: 400px;
  width: auto;
}

.new-collection-content {
  height: 400px;
  color: #f1f1f1;
  background-color: #111111;
  padding: 0 3em;
}

.new-collection-content h3 {
  font-size: 2.5em;
  font-weight: 300;
  text-transform: uppercase;
  line-height: 1.3;
  margin-bottom: .2em;
}

.new-collection-content p {
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
  font-size: .8em;
  letter-spacing: 1px;
}


/* layout for medium screens */

@media screen and (min-width: 810px) {
  .new-collection-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
}
<main class="new-collection-wrapper">
  <section class="new-collection-card">
    <div class="new-collection-card-img">
      <img src="http://www.petmania.ie/images/default-source/cat/petmania-kitten-1.jpg?sfvrsn=4" alt="new collection" alt="new collection">
    </div>
    <div class="new-collection-content">
      <h3>AW19 collection</h3>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Corporis, a sequi molestias nam odit sunt. Unde dolore fugit suscipit amet.</p>
      <a href="#" class="call-to-action"><span>JOIN</span></a>
    </div>
  </section>
  <!-- End of New Collection -->
</main>

1 个答案:

答案 0 :(得分:1)

flex-direction上的较小屏幕(请注意,媒体查询已更改为@media screen and (max-width: 810px)的{​​{1}}更改为-参见下面的演示:

new-collection-card
.new-collection-wrapper {
  background-color: #f1f1f1;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

.new-collection-card {
  width: 80%;
  margin: 5em 0;
  display: flex;
  align-items: center;
}

.new-collection-card-img img {
  height: 400px;
  width: auto;
}

.new-collection-content {
  height: 400px;
  color: #f1f1f1;
  background-color: #111111;
  padding: 0 3em;
}

.new-collection-content h3 {
  font-size: 2.5em;
  font-weight: 300;
  text-transform: uppercase;
  line-height: 1.3;
  margin-bottom: .2em;
}

.new-collection-content p {
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
  font-size: .8em;
  letter-spacing: 1px;
}


@media screen and (max-width: 810px) {
  .new-collection-card { /* change the flex direction */
    flex-direction: column;
  }
}