Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A flexbox grid of two flex items next to one [duplicate]

Tags:

html

css

flexbox

I am trying to have one div on the left and two on the right. The bottomright should always be below the topRight div. The topRight is the only div with a variable height.

I am currently trying to achieve this using flexbox als you can see in my code below.

I would like to have some directions.

.wrapper {
  display: flex;
  height: 100px;
}

.left {
  background-color: green
}

.topRight {
  background-color: yellow
}

.bottomright {
  background-color: red
}
<div class="wrapper">
  <div class="left">Left</div>
  <div class="topRight">TopRight</div>
  <div class="bottomright">Bottom</div>
  </div
like image 450
sanders Avatar asked Sep 17 '25 14:09

sanders


1 Answers

With a fixed height on the container, as you have in your code, you can use flex-direction: column and flex-wrap: wrap. The fixed height serves as a break point, telling flex items where to wrap.

.wrapper {
  display: flex;
  flex-direction: column;
  flex-wrap: wrap;
  height: 100px;
}

.left {
  flex: 0 0 100%; /* consumes full height of first column; forces siblings to wrap */
  background-color: lightgreen
}

/* variable height div */   
.topRight {
  background-color: yellow
}

.bottomright {
  flex: 1; /* consumes remaining space in column */
  background-color: red
}
<div class="wrapper">
  <div class="left">Left</div>
  <div class="topRight">TopRight<br>variable height</div>
  <div class="bottomright">Bottom</div>
  </div>
like image 75
Michael Benjamin Avatar answered Sep 20 '25 04:09

Michael Benjamin