-2

Can I make this structure with flexbox?

enter image description here

I give an example below with grid, but I want make this with flexbox.

.container {
    display: grid;
    grid-template-columns: auto auto auto;
    gap: 10px;
}
.grid-item {
    background-color: aquamarine;
}
.small {
    height: 200px;
}
.big {
    grid-row: span 10;
}
<div class="container">
    <div class="grid-item small">Cell 1</div>
    <div class="grid-item small">Cell 2</div>
    <div class="grid-item big">Cell 3</div>
    <div class="grid-item small">Cell 4</div>
    <div class="grid-item small">Cell 5</div>
    <div class="grid-item small">Cell 6</div>
    <div class="grid-item small">Cell 7</div>
    <div class="grid-item small">Cell 8</div>
    <div class="grid-item small">Cell 9</div>
    <div class="grid-item small">Cell 10</div>
    <div class="grid-item small">Cell 11</div>
    <div class="grid-item small">Cell 12</div>
</div>

What I want to achieve with flexbox:

width: 100%;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;

and

<div class="item">1</div>
<div class="item">2</div>
<div class="item big">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>

This is challenging because

  1. is with display flex
  2. in one row
TylerH
  • 20,799
  • 66
  • 75
  • 101
Stal
  • 45
  • 9
  • 1
    why the need for flexbox when you can use grid ? – dippas Jul 31 '23 at 20:18
  • as I said above "Don't ask me why I want to do this" because I was waiting for this logical question. But it's something I want to try, see it as a challenge. – Stal Jul 31 '23 at 20:20

1 Answers1

-1

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* debug */
body:before {
  content: '';
  inset: 0 auto 0 calc(50% - 1px);
  border-right: dashed 2px red;
  position: fixed;
}

.container {
  display: flex;
  flex-wrap: wrap;
  position: relative;
  gap: 8px;
  padding-right: calc(50% + calc(var(--gap) / 2));
  --gap: 8px;
}

.grid-item {
  width: calc(50% - calc(var(--gap) / 2));
  display: grid;
  place-items: center;
  background-color: coral;
}

.small {
  height: 200px;
}

.big {
  position: absolute;
  inset:0 0 0 calc(50% + var(--gap) / 2);
}
<div class="container">
  <div class="grid-item small">Cell 1</div>
  <div class="grid-item small">Cell 2</div>
  <div class="grid-item big">Cell 3</div>
  <div class="grid-item small">Cell 4</div>
  <div class="grid-item small">Cell 5</div>
  <div class="grid-item small">Cell 6</div>
  <div class="grid-item small">Cell 7</div>
  <div class="grid-item small">Cell 8</div>
  <div class="grid-item small">Cell 9</div>
  <div class="grid-item small">Cell 10</div>
  <div class="grid-item small">Cell 11</div>
  <div class="grid-item small">Cell 12</div>
</div>
imhvost
  • 4,750
  • 2
  • 8
  • 10
  • 1
    You used Grid System, it is not pure Flexbox solution either. – Md. Rakibul Islam Jul 31 '23 at 20:47
  • @Md.RakibulIslam friend, what are you talking about? About text alignment in flex elements? – imhvost Jul 31 '23 at 20:50
  • Someone else plus a comment – imhvost Jul 31 '23 at 20:54
  • Is there any way to do this without position absolute or any other way because I want to use “order” in big flexbox for media query? – Stal Aug 01 '23 at 06:24
  • 1
    @Md.RakibulIslam Regarding "You used Grid System". Take a closer look. `display: grid` is used only on the individual divs in order to center the text using `place-items: center`. The same could have been done with `display: flex; align-items: center; justify-content: center;` – Tim R Aug 01 '23 at 07:25