I want to create a page (HTML
) in a checkerboard style, so the first row has the image to the left of the content and the second row has the image to the right of the content.
Semantically, I can change the structure of the HTML to achieve this but is there a way to do this purely with CSS + Bootstrap 4 so the HTML doe not need to change.
I originally had a class "left-img
" and "right-img
" to achieve this but with no success.
Currently I have this in my CSS
, where every event element.
.checker:nth-child(even) .img-wrapper {
float:right;
}
.checker:nth-child(odd) .img-wrapper {
float:left;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row checker">
<div class="col-lg-6">
<div class="">
<h2>The Title</h2>
<div class="">
some text
</div>
</div>
</div>
<div class="col-lg-6 img-wrapper">
<img src="https://via.placeholder.com/140x100" alt="">
</div>
</div>
<div class="row checker">
<div class="col-lg-6">
<div class="">
<h2>The Title</h2>
<div class="">
some text
</div>
</div>
</div>
<div class="col-lg-6 img-wrapper">
<img src="https://via.placeholder.com/140x100" alt="">
</div>
</div>
Full example
My codepen https://codepen.io/s-mcdonald/pen/qBZvwyX?editors=1100