Utilize the basic Bootstrap layout for desktop, and for mobile (or any desired breakpoint), incorporate flex
and order
while applying display:contents
.
The order
attribute with the .order-X
classes in Bootstrap allows you to change the order of elements within the flex
setup. By using display: contents
, the element is removed from the accessibility tree, making the parent div
appear nonexistent, and its children appear directly in a flexible and orderly manner.
To achieve an output that resembles your image, consider this example:
.d-contents {
display: contents;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<div class="row">
<div class="col-12 col-md-6 bg-success">
A
</div>
&...
display: contents
Most browsers' current implementations will exclude any element with a display value of contents from the accessibility tree (though descendants remain). This results in the element not being announced by screen readers.
Source: display - CSS: Cascading Style Sheets | MDN
This approach may not be compatible with Internet Explorer.