responsive design - Div re-order with CSS -
does know of examples or tutorials on how achieve below:
as can see, want box 2 , box 3 re-order , swap positions on mobile
does have tips or advice?
depending on browsers need support use flex-box
. using media query screen size set order
of second , third boxes switch below screen width.
i've done pen short example. i'd recommend css tricks complete guide flexbox talks how use flex
far better can.
edit:
the basic principle set parent element (e.g., container) display: flex
; generates flexbox , allows set different parameters children.
using following html:
<div class="container"> <div class="box first"> box 1 </div> <div class="box second"> box 2 </div> <div class="box third"> box 3 </div> </div>
if set display:flex
on .container
, can set whether content should display in row or column, should wrap down line, have space between or around elements, etc. i've set main rule wrapping row using flex-flow (which shorthand 2 other flex properties, including flex-direction
need later), space between elements.
.container{ display:flex; flex-flow: row wrap; justify-content:space-between; }
i use media query when browser narrower specified width, flex-direction
gets changed row
column
@media screen , (max-width:600px){ .container { flex-direction:column } }
then, in same media query, need tell elements want re-order order should in:
@media screen , (max-width:600px){ .container { flex-direction:column } .second{ order: 3; } .third{ order: 2 } }
sometimes i've noticed order
needs defined elements, might need set first block , keep order: 1
. pen linked above, doesn't seem case here, keep eye out in other projects.
Comments
Post a Comment