skip to Main Content

I’m new to CSS and HTML. I made 3 boxes next to each other and I want to have 2 more rows of 3 boxes per row. I can’t seem to understand how to separate the rows. They always end up on the same row, distorted and I’ve been trying all morning to fix it. I will appreciate your help, thank you!

.container {
  display: flex;
  justify-content: space-between;
}

.box {
  width: 400px;
  height: 240px;
  background-color: #ccc;
  margin: 10px;
  transition: all 0.3s ease-in-out;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  overflow: hidden;
  text-align: justify;
  position: relative;
}

.box:hover {
  transform: scale(1.1);
}

.box .content {
  font-size: 10px;
  padding: 20px;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.box .title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
  position: justify;
  top: 50%;
  left: 50%;
}

.box:nth-child(1) {
  background-color: #fec10d;
}

.box:nth-child(2) {
  background-color: #0077c0;
}

.box:nth-child(3) {
  background-color: #b2d234;
}

.box img {
  position: relative;
  top: 1%;
  left: 50%;
  transform: translateX(-175%);
  height: 80px;
  width: 80px;
  object-fit: contain;
  margin-bottom: 5px;
  padding-bottom: 5px;
  margin: auto;
  display: block;
}
<div class="container">
  <div class="box">
    <div class="content">
      <img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
      <div class="title">TEAMWORK</div>
      <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
    </div>
  </div>
  <div class="box">
    <div class="content">
      <img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
      <div class="title">BUILDS TRUST</div>
      <div>Gains the trust of others through honesty and authenticity. Shows consistency between his/her words and actions, upholds professional codes of conduct, acts in accordance with the company’s policies, delivers on promises, and takes personal responsibility
        for decisions, actions, and mistakes.</div>
    </div>
  </div>
  <div class="box">
    <div class="content">
      <img src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD" alt="Care">
      <div class="title">CARE FOR OTHERS AND INCLUSION</div>
      <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
    </div>
  </div>
</div>

2

Answers


  1. Apply these changes to resolve this issue :

    .container {
      display: flex;
      justify-content: center;
    }
    
    /* add this style */
    
    .boxes {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
    }
    
    <div class="container">
          <div class="boxes">
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">TEAMWORK</div>
                <div>
                  Actively seeks opportunities to collaborate with and support
                  others. Builds relationships across the organization, shares
                  knowledge and experience, involve others and communicates
                  effectively.
                </div>
              </div>
            </div>
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">BUILDS TRUST</div>
                <div>
                  Gains the trust of others through honesty and authenticity. Shows
                  consistency between his/her words and actions, upholds
                  professional codes of conduct, acts in accordance with the
                  company’s policies, delivers on promises, and takes personal
                  responsibility for decisions, actions, and mistakes.
                </div>
              </div>
            </div>
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">CARE FOR OTHERS AND INCLUSION</div>
                <div>
                  Actively seeks opportunities to collaborate with and support
                  others. Builds relationships across the organization, shares
                  knowledge and experience, involve others and communicates
                  effectively.
                </div>
              </div>
            </div>
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">TEAMWORK</div>
                <div>
                  Actively seeks opportunities to collaborate with and support
                  others. Builds relationships across the organization, shares
                  knowledge and experience, involve others and communicates
                  effectively.
                </div>
              </div>
            </div>
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">BUILDS TRUST</div>
                <div>
                  Gains the trust of others through honesty and authenticity. Shows
                  consistency between his/her words and actions, upholds
                  professional codes of conduct, acts in accordance with the
                  company’s policies, delivers on promises, and takes personal
                  responsibility for decisions, actions, and mistakes.
                </div>
              </div>
            </div>
            <div class="box">
              <div class="content">
                <img
                  src="https://printeconline.sharepoint.com/:i:/r/sites/Marketing/Group%20Marketing%20Folder/Brand/Brand%20Materials/Values/Icons/Icons/Printec_Values_Icons_White_500x500px/Printec_Care_Icon_White_500x500px.png?csf=1&web=1&e=paSbKD"
                  alt="Care"
                />
                <div class="title">CARE FOR OTHERS AND INCLUSION</div>
                <div>
                  Actively seeks opportunities to collaborate with and support
                  others. Builds relationships across the organization, shares
                  knowledge and experience, involve others and communicates
                  effectively.
                </div>
              </div>
            </div>
          </div>
    
    Login or Signup to reply.
  2. Please use the below code.

    .container {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      gap: 20px;
    }
    
    .box {
      background-color: #ccc;
      transition: all 0.3s ease-in-out;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      overflow: hidden;
      text-align: justify;
      flex-basis: calc(32% - 6.67px); /* calculate flex-basis to account for gap */
      margin-bottom: 20px;
    }
    
    .box:hover {
      transform: scale(1.1);
    }
    
    .box .content {
      font-size: 10px;
      padding: 20px;
      color: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      height: 100%;
    }
    
    .box .title {
      font-size: 14px;
      font-weight: bold;
      margin-bottom: 10px;
      text-align: center;
    }
    
    .box:nth-child(1) {
      background-color: #fec10d;
    }
    
    .box:nth-child(2) {
      background-color: #0077c0;
    }
    
    .box:nth-child(3) {
      background-color: #b2d234;
    }
    
    .box img {
      position: relative;
      height: 80px;
      width: 80px;
      object-fit: contain;
      margin-bottom: 5px;
      padding-bottom: 5px;
    }

    below code:

    <div class="container">
      <div class="box">
        <div class="content">
          <img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
          <div class="title">TEAMWORK</div>
          <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
        </div>
      </div>
      <div class="box">
        <div class="content">
          <img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
          <div class="title">BUILDS TRUST</div>
          <div>Gains the trust of others through honesty and authenticity. Shows consistency between his/her words and actions, upholds professional codes of conduct, acts in accordance with the company’s policies, delivers on promises, and takes personal responsibility
            for decisions, actions, and mistakes.</div>
        </div>
      </div>
      <div class="box">
        <div class="content">
          <img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
          <div class="title">CARE FOR OTHERS AND INCLUSION</div>
          <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
        </div>
      </div>
      <div class="box">
        <div class="content">
          <img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
          <div class="title">TEAMWORK</div>
          <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
        </div>
      </div>
      <div class="box">
        <div class="content">
          <img src="https://img.freepik.com/free-vector/team-work-linear-design_1284-35744.jpg?w=1480&t=st=1676633574~exp=1676634174~hmac=17f549203c31724f00ab9d71befd333b53daa983a4f6974cbdb1ec4dbc3c3ad5" alt="Care">
          <div class="title">TEAMWORK</div>
          <div>Actively seeks opportunities to collaborate with and support others. Builds relationships across the organization, shares knowledge and experience, involve others and communicates effectively.</div>
        </div>
      </div>
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search