Flex boxes collapsing on top of the other

Viewed 76

I'm trying to make a text box collapse down the images, but the moment it does so in front of the images. Also I can't make the images collapse with space between them. I don't know what I'm doing wrong. I´ve tried different thing and search for a while but with no answers, I could only found things about collapsed margins, but not about this.

body{
  margin: 0;
  background-color: #120E0A;
  height: 1300px;
} 
 /*Check out*/
.checkouttext{
  display: flex;
  font-family: 'Abril Fatface', cursive;
  color: #d9bd66;
  font-size: 30px;
  height: 100px;
  width: 100%;
  align-items:center;
  justify-content: center;
  flex-wrap: wrap;
  flex-direction: row;
}
.checkoutimages{
  display: flex;
  width: 100%;
  height: 670px;
  align-items: center;
  justify-content: space-around;
  flex-wrap: wrap;
}
/*About*/
.about{
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;
  max-width: 1200px;
  max-height: 200px;
}
.abouttitle{
  font-family: 'Abril Fatface', cursive;
  color: #d9bd66;
  margin-left: 20px;
  font-size: 25px;
}
.abouttext{
  width: 1300px;
  color: white;
  margin-left: 15px;
  font-size: 18px;
}
<div class="checkouttext">
 Check out the new Halo merch!
</div>
<div class="checkoutimages">
 <img src="https://via.placeholder.com/300x500" alt="">
 <img src="https://via.placeholder.com/300x500" alt="">
 <img src="https://via.placeholder.com/300x500" alt="">
</div>

<!--About us-->
<div class="about">
 <div class="abouttitle">
   About us
 </div>
 <div class="abouttext">
   <p>Is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
    publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
 </div>
</div>

1 Answers

You are setting the height of the entire checkoutimages div to height: 670px; This means that this is the total height allocated to the div... even if the images are being wrapped onto another row. The elements following this div will be positioned based on that height, so if the content is bigger than 670px the next elements will be placed on top of them.

If you want the images within that div to have a max height of 670px, you can do it like this:

.checkoutimages img { max-height: 670px; }

Or if you want to add space before and after the checkoutimages div, you can add margin or padding:

.checkoutimages { margin-top: 65px; margin-bottom: 65px; }

Working Example:

body {
  margin: 0;
  background-color: #120E0A;
  height: 1300px;
}


/*Check out*/

.checkouttext {
  display: flex;
  font-family: 'Abril Fatface', cursive;
  color: #d9bd66;
  font-size: 30px;
  height: 100px;
  width: 100%;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  flex-direction: row;
}

.checkoutimages {
  display: flex;
  width: 100%;
  margin-top: 65px;
  margin-bottom: 65px;
  align-items: center;
  justify-content: space-around;
  flex-wrap: wrap;
}

.checkoutimages img {
  max-height: 670px;
  margin-bottom: 10px;
}


/*About*/

.about {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;
  max-width: 1200px;
  max-height: 200px;
}

.abouttitle {
  font-family: 'Abril Fatface', cursive;
  color: #d9bd66;
  margin-left: 20px;
  font-size: 25px;
}

.abouttext {
  width: 1300px;
  color: white;
  margin-left: 15px;
  font-size: 18px;
}
<div class="checkouttext">
  Check out the new Halo merch!
</div>
<div class="checkoutimages">
  <img src="https://via.placeholder.com/300x500" alt="">
  <img src="https://via.placeholder.com/300x500" alt="">
  <img src="https://via.placeholder.com/300x500" alt="">
</div>

<!--About us-->
<div class="about">
  <div class="abouttitle">
    About us
  </div>
  <div class="abouttext">
    <p>Is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived
      not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
      software like Aldus PageMaker including versions of Lorem Ipsum.</p>
    <p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content
      here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.
      Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
  </div>
</div>

Related