Currently, I am working on a blog layout using Bootstrap and have encountered an issue.
The specific layout requirement is to have the first two divs as col-md-3 (NORMAL), followed by the next 2 divs as col-md-6 (WIDE), then repeating this pattern for the next 4 divs as col-md-3 (NORMAL), the next 2 divs as col-md-6(WIDE), and so on.
I have attempted a method in CodePen (code below) which achieves the desired layout. However, due to my limited experience with jQuery, I believe there might be a more efficient way to accomplish this. Any guidance or assistance you can provide would be greatly appreciated!
HTML:
<div class="container">
<div class="row" id="blog">
<div>Normal</div>
<div class="">Normal</div>
<div class="">Wide</div>
... (more HTML code)
<div class="">Normal</div>
</div>
</div>
jQuery used:
$("#blog div").each(function(i) {
var newClass = 'col-md-3 red';
if (i == 2 || i == 3 || i == 8 || i == 9 || i == 14 || i == 15 || i == 20 || i == 21 || i == 26 || i == 27 || i == 32 || i == 33) {
newClass = 'col-md-6 blue';
}
$(this).addClass(newClass);
});