I have a problem regarding the following layouts
.box1 {
background: green;
height: 80px;
}
.box2 {
background: red;
height: 270px;
}
.box3 {
background: blue;
height: 200px;
}
.box4 {
background: yellow;
height: 100px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
</head>
<body>
<h1>Layout 1</h1>
<div class="container">
<div class="row">
<div class="col-md-8 box1">box1</div>
<div class="col-md-4 box2">box2</div>
</div>
<div class="row">
<div class="col-md-8 box3">box3</div>
<div class="col-md-4 box4">box4</div>
</div>
</div>
<hr />
<h1>Layout 2</h1>
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="box1">box1</div>
<div class="box3">box3</div>
</div>
<div class="col-md-4">
<div class="box2">box2</div>
<div class="box4">box4</div>
</div>
</div>
</div>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"></script>
</body>
</html>
Both are correct in some way and wrong in others
Layout 1 stacks the columns in the correct order (box1,2,3,4) on mobile screens, but on desktop screens there are undesired gaps between the content due to different content sizes. This is the current layout I am working with.
Layout 2 does not show the gaps of layout 1, but the columns do not stack correctly (box1,3,2,4).
I understand why both layouts behave the way they do.
How can you create a layout that combines the desired results of both layouts using bootstrap or plain css? (note that the project I am working on uses an older version of bootstrap).
Thanks
Edit
The box heights can vary from page to page. I have just set them in a way that illustrates the problem.