html - flexbox order: I want box to open under a element which is not a sibling -


i want yellow under blue when screen size small.

i know why dont work now, since yellow not sibling other boxes, can fix this?

https://jsfiddle.net/0vbdcms0/

.container1 {    display: flex;    flex-flow: column;  }    .container2 {    display: flex;    flex-flow: row;  }    .box {    border: 1px solid black;    width: 50px;    height: 50px;    margin: 5px 5px 5px 5px;  }    #b1 {    background-color: red;  }    #b2 {    background-color: blue;  }    #b3 {    background-color: green;  }    #b4 {    background-color: yellow;  }    @media screen , (max-width:500px) {  .container2 {    display: flex;    flex-flow: column;  }    #b1 {      order: 1;      -webkit-order: 1;    }      #b2 {      order: 2;      -webkit-order: 2;    }      #b3 {      order: 4;      -webkit-order: 4;    }      #b4 {      order: 3;      -webkit-order: 3    }  }
<div class="container1">    <div class="container2">      <div class="box" id="b1"></div>      <div class="box" id="b2"></div>      <div class="box" id="b3"></div>    </div>    <div class="box" id="b4"></div>  </div>

i need add more text satisfy so, think got relevant info in text above :)

using order not work because order in relation container not dom.

the css order property specifies order used lay out flex items in flex container. elements laid out in ascending order of order value. elements same order value laid out in order in appear in source code.

mdn - "order"

css grid can though.

codepen demo

.container {    padding: 5px;    display: grid;    width: 500px;    margin: 1em auto;    grid-auto-columns: 50px;    grid-auto-rows: 50px;    grid-gap: 5px;  }    .box {    border: 1px solid black;    width: 50px;    height: 50px;  }    #b1 {    background-color: red;    grid-column-start: 1;    grid-column-end: 2;  }    #b2 {    background-color: blue;    grid-column-start: 2;    grid-column-end: 3;  }    #b3 {    background-color: green;    grid-column-start: 3;    grid-column-end: 4;  }    #b4 {    background-color: yellow;    grid-column-start: 1;    grid-column-end: 2;  }    @media screen , (max-width: 500px) {    #b1,    #b2,    #b3,    #b4 {      grid-column-start: 1;      grid-column-end: 2;    }    #b3 {      grid-row-start: 4;      grid-row-end: 5;    }    #b4 {      grid-row-start: 3;      grid-row-end: 4;    }  }
<div class="container">    <div class="box" id="b1"></div>    <div class="box" id="b2"></div>    <div class="box" id="b3"></div>    <div class="box" id="b4"></div>  </div>

it might possible in flexbox necessary properties not yet supported in browsers. think it's firefox of time of writing.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -