微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用CSS flexbox重新排序整个页面

我需要使用Flex更改移动设备整个页面的顺序.我可以在单个容器中使用它,但是可以在页面上使用所有容器吗?这是一个例子:
.outer {
  display: flex;
  flex-direction: column;
}
#a {
  order: 4;
  background: #ccc;
}
#b {
  order: 1;
  background: #aaa;
}
#c {
  order: 3;
  background: #d33;
}
.one {
  order: 2;
  background: #aaa;
}
.two {
  order: 5;
  background: #aaa;
}
<div class="outer">
  <div id="flex">
    <div id="a">A</div>
    <div id="b">B</div>
    <div id="c">C</div>
  </div>
  <div id="flex2">
    <div class="one">Show me 2nd</div>
    <div class="two">Show me 5th</div>
  </div>
</div>

“Show me 2nd”和“Show me 5th”只是坐在最后而不是新订单中.要确认,无法更改HTML.

JsFiddle

解决方法

您不能对不共享同一容器的元素应用带有flex的订单:

The ‘order’ property controls the order in which flex items appear within their flex container,by assigning them to ordinal groups.

Soucre

您可以更改HTML结构,因此所有元素将共享同一个容器,然后订单规则将起作用.

原文地址:https://www.jb51.cc/css/217693.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。