Change the order of DIV (Structure) using CSS flex

Change the order of DIV (Structure) using CSS flex

We have many things to do as a frontend developer but the very hated part is to change the structure of the HTML with the same structure but the question here is HOW?

By using javascript? = NO

By using HTML = NO, I would love to but I can't.

By using CSS = YES YES YES we can by using CSS3.

CSS3 had improved and helped a lot to make such thing possible.

Mainly FLEX is one of the most used and loved CSS property which is been used.

so let's take a look a code directly.

HTML:

<div class="wrapper">
  <div class="box one">1</div>
  <div class="box two">2</div>
  <div class="box three">3</div>
  <div class="box four">4</div>
  <div class="box five">5</div>
</div>

CSS(SASS):

.wrapper
  border: 1px solid #ccc
  width: 500px
  display: flex
  height: 200px
.box
  height: 30px
  width: 30px
  color: white
  padding: 10px
  font-weight: 600
.one
  background-color: red
  order: 2
.two
  background-color: blue
  order: 1
.three
  background-color: green
  order: 3
.four
  background-color: orange
  order: 4
.five
  background-color: black
  order: 5
@media (max-width: 767px)
  .one
    background-color: red
    order: 5
  .two
    background-color: blue
    order: 4
  .three
    background-color: green
    order: 3
  .four
    background-color: orange
    order: 2
  .five
    background-color: black
    order: 1

USEFUL LINKS:

Codepen URL: https://codepen.io/atulya/pen/BvVVxo

SUPPORT: 

CANIUSE: https://caniuse.com/#feat=flexbox

MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/orderppy

Hope you like it, and if you like it please do share it ;)

Happy layout ordering.

To view or add a comment, sign in

More articles by Atul Bhalerao

  • Stop iframe video playback - YouTube using jQuery

    Hi All In day to day life most of the frontend develop are always fighting to stop video which is in the modal popup…

  • Bootstrap 5 Navigation Menu Solutions

    The was one of the major issue for mega menu development which is been resolved not have a look Looking for old…

  • Remote debug Android devices

    Remote debug live content on an Android device from your Windows, Mac, or Linux computer. This tutorial teaches you how…

  • How to cast Android screen in Ubuntu

    - For designers and developers only Prerequisites An Android device with at least a 5.0 version It is necessary to…

    4 Comments
  • console.log(); vs window.alert();

    console.log() All modern web browsers, Node.

  • Variable in CSS, seriously?

    When it comes to style guide from designer, we need sass/scss or less to write it, but here we can do it as we did…

  • Get rid of 404 page not found Page

    If you have a domain name but no space, which shows up with 404 PAGE NOT FOUND - Then what is the solution Here is the…

  • How can I modify or disable the HUD's use of the Alt key?

    Yes this is what I want, The HUD is really annoying. Here are the steps for the same.

  • On Click Loader using CSS and Js

    When we think about the request and the response on clicking the button it looks pretty simple but to show the user the…

  • How to use calc in CSS

    Summary: People who know and don't know about it, CSS calc() is used for simple calculations to regulate CSS property…

    1 Comment

Explore content categories