CSS change div order without flex

前端 未结 3 1522
失恋的感觉
失恋的感觉 2021-01-06 08:00

given a HTML of:

1
2
3
相关标签:
3条回答
  • 2021-01-06 08:17

    You can use left and float: left;

    .class {
        position: relative;
        float: left;
        width: 25%;
       }
    
      .class:nth-child(1) {
        left: 75%;
      }
    
      .class:nth-child(2) {
        left: 25%;
      }
    
      .class:nth-child(3) {
        left: -25%;
      }
    
      .class:nth-child(4) {
        left: -75%;
      }
    
    0 讨论(0)
  • 2021-01-06 08:25

    You can use grid layout, which has similar order properties.

    .boxes {
      display: grid;
    }
    
    .class:nth-of-type(1) {
      order: 2;
    }
    
    .class:nth-of-type(2) {
      order: 4;
    }
    
    .class:nth-of-type(3) {
      order: 1;
    }
    
    .class:nth-of-type(4) {
      order: 3;
    }
    <div class="boxes">
      <div class="class">1</div>
      <div class="class">2</div>
      <div class="class">3</div>
      <div class="class">4</div>
    </div>

    0 讨论(0)
  • 2021-01-06 08:29

    There are many possibilities. The sanest, of course, is to use flex, but if you don't want that, one way is to do it like this.

    .container {display: table;}
    .class {display: table-row;}
    .class:nth-child(3) {display: table-header-group;}
    .class:nth-child(2) {display: table-footer-group;}
    <div class="container">
      <div class="class">1</div>
      <div class="class">2</div>
      <div class="class">3</div>
      <div class="class">4</div>
    </div>

    0 讨论(0)
提交回复
热议问题