I am facing an issue with 3 blocks in a row - a large block, a smaller block that can expand, and a third block placed under the first block. When the smaller block expands, the top of the third block moves to match the bottom of the expanding div. However, I need the third block to stay at the bottom of the first block.
I have tried different configurations using Bootstrap columns, but I am struggling to maintain the desired layout on mobile. I have also explored using card-columns but faced limitations in customizing the width and order of appearance on mobile devices.
To illustrate the problem, I have created a fiddle: https://jsfiddle.net/k53rnvpb/1/
$('.expand').click(function() {
$('.block-2').toggleClass('height-300');
})
.row {
background: #f8f9fa;
margin-top: 20px;
}
[class^="col-"] {
border: solid 1px #6c757d;
padding: 10px;
}
.block-1 {
height: 200px;
}
.block-2 {
height: 150px;
}
.block-3 {
height: 200px;
}
.height-300 {
height: 300px;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-12 col-sm-8 block-1">
Block 1
</div>
<div class="col-12 col-sm-4 block-2">
Block 2
<p>I need to be between block 1 and 3 on mobile</p>
<button class='btn btn-primary expand'>Expand</button>
</div>
<div class="col-12 col-sm-8 block-3">
Block 3
<p>If block 2 expands i still need to be attached to block 1</p>
</div>
</div>
</div>
I am seeking a solution to prevent the bottom block from moving when the other block expands or to find a clean way to position the expanding block between the other two blocks on mobile devices.
I hope the issue is clear, and I appreciate any assistance.