I would like to have the order of divs on my site like on the image:
On the top part of image the red div should be floated to left and blue and green to right. Important for me is to have green div below blue, no matter what size of red div is, so clear: both
is not fine. I tried with flexbox but also with no success. I also tried wrapping blue and green div in another div, name it rightColumn
but then I am not able to achieve the lower part of image: on mobile devices (I know media only
CSS rule so this is fine) I want to have this order: blue, red, green, each of 100% width.
How to achieve that in pure CSS? Is it even possible?
4
Answers
A mix of CSS grids and flexbox for mobile should accomplish this:
You can change the order on the mobile version (which you should stick into a
@media
query, but it’s stack overflow so for safety I simulated it with a class instead) by modifying theorder
property, and on desktop, you can do it by changing the values of the columns or rows in thegrid-template
.Docs for
grid-template
: https://developer.mozilla.org/en-US/docs/Web/CSS/grid-templateDocs for
order
: https://developer.mozilla.org/en-US/docs/Web/CSS/orderYou can do this with
order:1
(order CSS property) by applying flex to its parent.Note: If you want to use Bootstrap then it will be very smooth.
Bootstrap Orders
For more detail please refer to this link CSS Order
You may use
grid
and resetorder
andgrid-template-columns
for bigger screen.here is an example with a break point at 768px (i used html5 tags elements for the demo, but feel free to use your own markup and class/ids )
An alternative to grid would be using flex with display contents: