Bootstrap vertical alignment with column wrapping and different height

Viewed 289

I would like to present 4 div with size "col-md-6". If all of them got the same height, all is working (the result is like there)

1 2
3 4

But if one of them (example with 1 div) is taller than others, then result change, and the 3 is not starting at the bottom of the number 3 div

I got this :

12
  2
  4
  4
3

I want this :

12
32
  4

enter image description here

here- Codepen

Thank you

<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>

<div class="container-fluid">
  <h1>Push and Pull</h1>
  <p>Resize the browser window to see the effect.</p>
  <div class="row">
    <div class="col-md-6" style="background-color:red;">A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A</div>
    <div class="col-md-6" style="background-color:green;">B<br>B<br>B<br>B<br>B<br>B</div>
    <div class="col-md-6" style="background-color:yellow;">C<br>C<br>C<br>C<br>C<br>C</div>
    <div class="col-md-6" style="background-color:purple;">D<br>D<br>D<br>D<br>D<br>D</div>
  </div>
</div>

1 Answers

You can try this piece of code

I've just added two cols in your row :

Before :

<div class="row">
    <div class="col-md-6" style="background-color:red;">...</div>
    <div class="col-md-6" style="background-color:green;">...</div>
    <div class="col-md-6" style="background-color:yellow;">...</div>
    <div class="col-md-6" style="background-color:purple;">...</div>
</div>

After :

<div class="row">
    <div class="col-md-6" style="padding: 0">
        <div style="background-color:purple;">...</div>
        <div style="background-color:red;">...</div>
    </div>
    <div class="col-md-6" style="padding: 0">
        <div style="background-color:green;">...</div>
        <div style="background-color:yellow;">...</div>
    </div>
</div>

I hope answering to your request

Related