Joren Polfliet
Joren Polfliet

Reputation: 127

Flexbox/Float - 2 1 2 Layout

I'm trying to create a 2 1 2 layout using Flexbox or floats as seen in the image added to this question. Is there any way to do this successfully using just an ordered list of items?

<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

enter image description here

1,2,4,5 are the same in size and 3 is the same width as the other blocks.

I'm trying to accomplish this using Flexbox but I can't seem the get 2 under 1 and 5 under 4.

Upvotes: 3

Views: 1369

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122087

You could do this with flex-direction: column and flex-wrap: wrap but i think you must set fixed height on parent

body, html, ul {
  margin: 0;
  padding: 0;
}
* {
  box-sizing: border-box;
}
ul {
  display: flex;
  height: 100vh; 
  list-style-type: none;
  flex-direction: column;
  flex-wrap: wrap;
}
li {
  flex: 0 0 50%;
  border: 1px solid black;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 50px;
}
li:nth-child(3) {
  flex: 0 0 100%;
}
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
</ul>

Upvotes: 6

Related Questions