1

How can I make the first .item (green box) 100% height ?

* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
.item {
border: 1px solid red;
background: #8282e0;
width: 50%;
}
.item:nth-child(1) {
background: #a6f7a6;
height: 100%;
}
.item:nth-child(3) {
margin-left: 50%;
}
<div class="wrap">
  <div class="item">
<h3>Item Title</h3>
  </div>
  <div class="item">
<h3>Item Title</h3>
  </div>
  <div class="item">
<h3>Item Title</h3>
  </div>
</div>

Codepen - https://codepen.io/afelixj/pen/eavVJw

Felix A J
  • 6,300
  • 2
  • 27
  • 46
  • Do you have to use flexbox or can you use grid? – Joe B. May 16 '19 at 05:25
  • Flexbox isn't going to be able to do this without changing your markup. As @JoeB. says, grid can do this. – ray May 16 '19 at 05:27
  • you can't do that when a flexbox *wraps*. CSS grids do better.. a similar requirement [here](https://stackoverflow.com/questions/55604932/ordering-flex-items) but along with ordering too – kukkuz May 16 '19 at 05:38
  • There is no need of all this css to get this result, just change the structure and remove all the CSS, Check my answer bewlow – Atul Rajput May 16 '19 at 05:59

4 Answers4

4

This is how I would do it (I don't know a way to make it work if you need to put the three headers exactly under each other, like rendering them with a for loop)

* {
  box-sizing: border-box;
}

.wrap {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
  flex: 1;
}

.itemCont {
  display: flex;
  background: #8282e0;
  flex: 1;
  flex-direction: column;
}

.item {
  display: flex;
  border: 1px solid red;
  background: #5691f3;
  flex: 1;
}
<div class="wrap">
  <div class="itemCont">
    <div class="item">
      <h3>Item Title</h3>
    </div>
  </div>
  <div class="itemCont">
    <div class="item">
      <h3>Item Title</h3>
    </div>
    <div class="item">
      <h3>Item Title</h3>
    </div>
  </div>
</div>
ganjim
  • 1,234
  • 1
  • 16
  • 30
1

This can be achieved by changing flex-direction to column and applying a fixed height to .wrap

* {
    box-sizing: border-box;
}
.wrap {
    display: flex;
    flex-wrap: wrap;
    flex-direction: column;
    height: 123px;
}
.item {
    border: 1px solid red;
    background: #8282e0;
    width: 50%;
}
.item:nth-child(1) {
    background: #a6f7a6;
    height: 100%;
}
<div class="wrap">
  <div class="item">
<h3>Item Title</h3>
  </div>
  <div class="item">
<h3>Item Title</h3>
  </div>
  <div class="item">
<h3>Item Title</h3>
  </div>
</div>
AlliterativeAlice
  • 11,841
  • 9
  • 52
  • 69
1

* {
  box-sizing: border-box;
}

.wrap {
  display: flex;
  flex-wrap: wrap;
}

.item {
  border: 1px solid red;
  background: #8282e0;
  flex:1;
}

.item-inner {
  flex: 1;
  justify-content:center;
  height:100px;
}
.wrap-inner{
  display: flex;
  flex-wrap: wrap;
  flex-direction:column;
}
.item:nth-child(1) {
  background: #a6f7a6;
  height: 200px;
}

.item:nth-child(3) {
  margin-left: 50%;
}
<div class="wrap">
  <div class="item item-outer">
    <h3>Item Title</h3>
  </div>
  <div class="item wrap-inner">
    <div class="item-inner">
      <h3>Item Title</h3>
    </div>
    <div class="item-inner">
      <h3>Item Title</h3>
    </div>
  </div>
</div>

This would be apt use of flex property and altering the height.

manish kumar
  • 4,412
  • 4
  • 34
  • 51
1

There is no need of the extra CSS, just change the structure and Give background colors as per your need.

* {
box-sizing: border-box;
}
.wrap {
display: flex;
flex-wrap: wrap;
}
.item {
border: 1px solid red;background: #8282e0;
}
.wrap > .item{width: 50%;}
<div class="wrap">
  <div class="item">
    <h3>Item Title</h3>
  </div>
  <div class="item">
  <div class="item">
    <h3>Item Title</h3>
  </div>
  <div class="item">
    <h3>Item Title</h3>
  </div>
  </div>
</div>
Atul Rajput
  • 4,073
  • 2
  • 12
  • 24