Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you specify the order of wrapped elements in CSS flex?

I have a <div> that uses CSS flex to keep it responsive.

I am looking for a way to specify the order that elements are wrapped in.

For example, I need

1 - 2 - 3

To become

1
3
2

When fully wrapped.

Current code: https://jsfiddle.net/g0L44e5b/

Is this possible?

like image 234
Chris Avatar asked Jan 01 '26 00:01

Chris


1 Answers

yes you can , use order property:

body {
  display:flex;
  flex-flow:column;
  }
p:last-child{
  order:1;
  }
p:nth-child(2) {
  order:2;
    }
<p>1</p>
<p>2</p>
<p>3</p>

here is an handy ressource https://css-tricks.com/snippets/css/a-guide-to-flexbox/


edit after your edit

wrap and mediaquerie can be used :

body {
  display:flex;flex-wrap:wrap;
  }
p {
  flex:1;
  min-width:380px;
  margin:10px;
  border:solid;
}
@media screen and (max-width : 800px) {
p:last-child{
  order:1;
  }
p:nth-child(2) {
  order:2;
    }
}
<p>1</p>
<p>2</p>
<p>3</p>
like image 99
G-Cyrillus Avatar answered Jan 02 '26 15:01

G-Cyrillus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!