-2

I am trying to do exactly this:

Col span 2 rows

Where my mark up is:

 <div>
   <div>A</div>
   <div>B</div>
   <div>C</div>
</div>

Is this possible with grid, bootstrap or flex? Without changing the order of elements?

j00m
  • 491
  • 5
  • 20

3 Answers3

1

I think it has a lot of way to do.

And one of that way is using grid. then use grid-template for solve this question

.container {
  display: grid;
  grid-template:
    "a b"
    "c b";
}

.a {
  grid-area: a;
  background: red;
}

.b {
  grid-area: b;
  background: blue;
}

.c {
  grid-area: c;
  background: green;
}

or using grid-area

.container {
  display: grid;
}

.a {
  background: red;
}

.b {
  grid-area: 1 / 2 / 3;
  background: blue;
}

.c {
  background: green;
}

Earn Asdsa
  • 172
  • 2
  • 9
1

.wrapper {
  height: 300px;
  display: grid;
  grid-template-columns: repeat(2, 50%);
}

.wrapper div {
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrapper div:nth-child(1) {
  background-color: green;
}

.wrapper div:nth-child(2) {
  grid-row: 2 span;
  background-color: blue;
}

.wrapper div:nth-child(3) {
  background-color: red;
}
<div class="wrapper">
  <div>A</div>
  <div>B</div>
  <div>C</div>
</div>

Is that something you wanted to achive ? "Grid" is kind of made for this kind of situations.

As for bootstrap - last version uses "flex" as default.

Justyna Skrajna
  • 90
  • 1
  • 11
0

Using one more div will be the solution, do the following.

Hope it is useful.

https://codepen.io/Olmedo12/pen/WNdGOMB

HTML

<div class="container">
      <div class="subcontainer">
        <div class="box blue">BOX 1</div>
        <div class="box red">BOX 3</div>
      </div>
      <div class="box green">
         Box 2
      </div>
    <div>

CSS

.container {
  display: flex;
}

.box {
  width: 60px;
  height: auto;
}

.red {
  background: red;
}

.blue {
  background: blue;
}

.green {
  background: green;
}
EDev
  • 400
  • 3
  • 10
  • Unfortunately the order of elements needs to be A, B, C as above (for keyboard/screenreader users). You have changed the order to A, C, B which I cannot do. – j00m Aug 09 '22 at 19:08
  • Can't you just change the name/content of the div's? – EDev Aug 09 '22 at 19:11