Figuring this out was quite challenging. After some brainstorming, I managed to come up with a solution that involves integrating a bit of jQuery for the desired outcome.
Below is the html structure where I made some modifications to the columns:
<div class="container text-center">
<div class="row">
<div class="col-sm-4 col-lg-3 col-lg-push-9">
<div class="alert alert-warning">A</div>
</div>
<div class="col-sm-8 col-lg-6 col-lg-pull-0 big">
<div class="alert alert-danger">C</div>
</div>
<div class="col-sm-4 col-lg-3 col-lg-pull-9 small">
<div class="alert alert-info">B</div>
</div>
</div>
</div>
Additionally, I have included the jQuery script that dynamically switches the display based on the window width:
<script>
var $iW = $(window).innerWidth();
if ($iW < 768){
$('.small').insertBefore('.big');
}else{
$('.big').insertBefore('.small');
}
</script>
It is important to note that the jQuery used here is not directly linked to window resizing post document load, but this can be adjusted by incorporating $(window).resize(function(){});
If you prefer to avoid JavaScript altogether, there is an alternative solution that involves duplicating one of the blocks. This method can work well if the content within that block is static. Below is the modified html structure:
<div class="container text-center">
<div class="row">
<div class="col-sm-4 col-lg-3 col-lg-push-9">
<div class="alert alert-warning">A</div>
</div>
<div class="col-sm-4 small-screen-only">
<div class="alert alert-info">B</div>
</div>
<div class="col-sm-8 col-lg-6 col-lg-pull-0 big">
<div class="alert alert-danger">C</div>
</div>
<div class="col-sm-4 col-lg-3 col-lg-pull-9 small">
<div class="alert alert-info">B</div>
</div>
</div>
</div>
The CSS code provided ensures the duplicated block B only displays on smaller screens:
.small-screen-only{
display: none;
}
@media all and (max-width: 767px)
{
.small-screen-only{
display: block
}
.small{
display: none;
}
}
Personally, I recommend the CSS approach as it aligns better with the browser's native functionality. Even for dynamically added block content, there are ways to adapt this setup to suit your requirements.