How do you put a div that’s inside a container under each other?

Asked

Viewed 56 times

-2

I’m having the following problem, my Divs are getting online, I’ve tried several ways to try to insert one under the other, but it still doesn’t work.

inserir a descrição da imagem aqui

The correct would be to stay in the format below:

inserir a descrição da imagem aqui

html,
body {
  width: 100%;
  height: 100%;
  margin-left: -50;
  padding: 0; 
}

.jumbo {
  background-image: url(https://unsplash.it/600/300);
  background-size: 100% 100%;
  background-repeat: no-repeat; 
  width: 100%;
  height: 100%;
  background-position: 0% 0%
}

.container {
 width: 100%;
  align-items: center;  
  padding-top: 12.0cm;
  float:right;
  box-sizing: border-box;
  border: 1px solid red;
  display: flex;
  align-items: right;
  flex-wrap: wrap;
  padding-top: 1rem;
}

.box {
  width: calc(20% - 2rem);
  height: 10rem;
  margin: 1.0em 1em;
  box-sizing: border-box;
  display: flex;
  position: relative;
}

.p1,
.p2,
.p3 {
   display: flex;
  align-items: center;
  justify-content: center;
  color: blue;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
  border-bottom-left-radius: 25px;
  border-top-left-radius: 25px;
  background-color: white;
}

.p1 {
  flex-grow: 1;
  background-color:#DCDCDC;
  color:black;
  position: right;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}

.p2 {
  flex-grow: 2;
  background-color: black;
  position: absolute;
  color:#DCDCDC;
  right: 0;
  left: 0;
  top: 0;
  height: 40px;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}
<div class="jumbo">
  <div class="container">
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>


  </div>
</div>

3 answers

1


Puts the .container with width: 50%. Obviously you still need to treat the responsiveness for smaller screens....

inserir a descrição da imagem aqui

html,
body {
  width: 100%;
  height: 100%;
  /* margin-left: -50; */
  padding: 0; 
  margin: 0;
}

.jumbo {
  background-image: url(https://unsplash.it/600/300);
  background-size: 100% 100%;
  background-repeat: no-repeat; 
  width: 100%;
  height: 100%;
  background-position: 0% 0%
}

.container {
 /* width: 100%; */
  align-items: center;  
  padding-top: 12.0cm;
  float:right;
  box-sizing: border-box;
  border: 1px solid red;
  display: flex;
  align-items: right;
  flex-wrap: wrap;
  padding-top: 1rem;


  width: 50%;
  height: 100%;

}

.box {
  width: calc(20% - 2rem);
  height: 10rem;
  margin: 1.0em 1em;
  box-sizing: border-box;
  display: flex;
  position: relative;
}

.p1,
.p2,
.p3 {
   display: flex;
  align-items: center;
  justify-content: center;
  color: blue;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
  border-bottom-left-radius: 25px;
  border-top-left-radius: 25px;
  background-color: white;
}

.p1 {
  flex-grow: 1;
  background-color:#DCDCDC;
  color:black;
  position: right;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}

.p2 {
  flex-grow: 2;
  background-color: black;
  position: absolute;
  color:#DCDCDC;
  right: 0;
  left: 0;
  top: 0;
  height: 40px;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}
<div class="jumbo">
  <div class="container">
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>


  </div>
</div>

1

Hi, I took your code and made some adjustments so you have a path. Take a look at the grid display and flex display.

 <div class="jumbo">
<div class="container">
  <div class="box">
    <div class="p1">
      100%
    </div>
    <div class="p2">
      SAMSUNG
    </div>
  </div>
 
  <div class="box">
    <div class="p1">
      100%
    </div>
    <div class="p2">
      SAMSUNG
    </div>
  </div>

  <div class="box">
    <div class="p1">
      100%
    </div>
    <div class="p2">
      SAMSUNG
    </div>
  </div>
  <div class="box">
    <div class="p1">
      100%
    </div>
    <div class="p2">
      SAMSUNG
    </div>
  </div>


</div>

And the CSS:

 html,
body {
  padding: 0;
  margin: 0;
}

.jumbo {
  float: right;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
}

.container {
  width: 100%;
  display: grid;
  grid-template-columns: 50% 50%;
  column-gap: 20px;
}

.box {
  width: 300px;
  height: 10rem;
  margin: 1.0em 1em;
  box-sizing: border-box;
  position: relative;
  display: flex;
}

.p1,
.p2,
.p3 {
  text-align: center;
  color: blue;
  font-family: sans-serif;
  font-weight: bold;
  background-color: #ffffff;
  border-bottom-left-radius: 25px;
  border-top-left-radius: 25px;
  background-color: white;
}

.p1 {
  width: 100%;
  background-color: #DCDCDC;
  color: black;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}

.p2 {
  width: 100%;
  background-color: black;
  position: absolute;
  color: #DCDCDC;
  right: 0;
  left: 0;
  top: 0;
  height: 40px;
  border-bottom-right-radius: 25px;
  border-top-right-radius: 25px;
}

Example running: https://jsfiddle.net/ec2f14q7/

Good studies!

0

Hi Gabriel Passion Justin, all right? You need to take the box of the brands ( Samsung,Asus,dell..) and put inside a col-6 and the other side inside another col-6 but all this inside a Row. Look at the change I made in your HTML, I hope I helped.

<div class="jumbo">
  <div class="container row">
    <div class="box col-md-6">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>
    <div class="box">
      <div class="p1">
        SAMSUNG
      </div>
      <div class="p2">
        50%
      </div>
    </div>
    <div class="box">
      <div class="p1">
        100%
      </div>
      <div class="p2">
        SAMSUNG
      </div>
    </div>


  </div>
</div>
  • What is col-6? I didn’t see anything in his CSS, nor in yours

  • Hi, Caetano Sincero, col-6 is bootstrap, look at the third line <div class="box col-Md-6"> . Good reference: https://www.w3schools.com/bootstrap4/default.asp

Browser other questions tagged

You are not signed in. Login or sign up in order to post.