I am using Bootstrap 4, but if it works on version 3, it should work on v4.
I have 2 divs within a column like so:
<div class="row">
<div class="col-xs-12">
<div>TOP ON DESKTOP, BOTTOM ON MOBILE</div>
<div>BOTTOM ON DESKTOP, TOP ON MOBILE</div>
</div>
</div>
Is there a way I can get the divs to swap around on a mobile device? I do not want to use any JavaScript here; I would like to use Bootstrap classes only, if possible.
If it is not possible with Bootstrap, then CSS-only please.
This can be achieved using CSS'
flexbox
..col-xs-12
with the following properties:display: flex;
tells the children to use theflexbox
modelflex-direction: column-reverse;
will ensure that the children flow from bottom to top (instead of the default left to right)Run the below Snippet in full screen and resize the window to see the order of the elements change.
A Bootstrap method
This can also be achieved using Bootstrap:
d-flex
to make the container use flexboxflex-column-reverse
to order the children in reverse order on small screensflex-sm-column
to order the children in normal order on larger screensThe following code works for me: