栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

根据设备宽度更改CSS的div顺序

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

根据设备宽度更改CSS的div顺序

得益于出色的flexbox规范,这在CSS中是可行的。使用

order
flex-flow
属性,我们可以实现您想要的。IE11和所有常绿浏览器无前缀,将支持此功能。IE10前缀
-ms-order
,不支持
flex-flow

该解决方案考虑了您列出的所有约束:

  • 将指定顺序的元素列表显示为一行。
  • 如果窗口太小,请更改它们以显示在列中。
  • 当元素在列中显示时,更改它们的顺序。

由于堆栈代码段的限制,您需要以整页模式查看演示,并调整浏览器的大小以查看效果。

.container div {    width: 100px;    height: 50px;    display: inline-block;}.one { background: red; }.two { background: orange; }.three { background: yellow; }.four { background: green; }.five { background: blue; }@media screen and (max-width: 531px) {    .container { display: flex; flex-flow: column; }    .five { order: 1; }    .four { order: 2;  }    .three { order: 3; }    .two { order: 4; }    .one { order: 5 }}<div >    <div >I'm first</div>    <div >I'm second</div>    <div >I'm third</div>    <div >I'm fourth</div>    <div >I'm fifth</div></div>

如果您倾向于冗长的CSS,也可以在

flex-flow: column-reverse
不将
order
属性分配给每个div的情况下直接使用。相同的演示限制适用;全屏查看此演示,并相应地调整浏览器窗口的大小。

.container div {    width: 100px;    height: 50px;    display: inline-block;}.one { background: red; }.two { background: orange; }.three { background: yellow; }.four { background: green; }.five { background: blue; }@media screen and (max-width: 531px) {    .container { display: flex; flex-flow: column-reverse; }}<div >    <div >I'm first</div>    <div >I'm second</div>    <div >I'm third</div>    <div >I'm fourth</div>    <div >I'm fifth</div></div>

值得指出的是,这

flex-flow
是同时包含
flex-direction
flex-wrap
属性的简写属性。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495345.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号