html - 列反向中的弹性排序
问题描述
我有以下标记:
.colReverse {
display: flex;
/* flex-direction: column-reverse; */
flex-direction: column;
}
.border:after{
content: "";
display: block;
width: 80%;
background-color: black;
height: 1px;
margin: 60px auto 0px;
order: 3;
}
<div class="colReverse border">
<div>Item 1</div>
<div>Item 2</div>
</div>
在桌面上,flex-direction
是column
,所以项目,项目,边框。这就是我想要的(边界总是最后的)。
在移动设备上,我将其更改flex-direction
为column-reverse
,这显然将边框置于项目之上。
因为我总是希望边框位于底部,所以我指定它order
是第三个(或最后一个)。然而,这行不通?想法为什么?
解决方案
从column
to切换column-reverse
不会自动发生。你需要一个触发器。最简单的解决方案是媒体查询。
因此,只需在媒体查询中添加第二条规则,以使您的边框在较小的屏幕上保持原位。
.colReverse {
display: flex;
flex-direction: column;
}
.border::after {
content: "";
width: 80%;
background-color: black;
height: 1px;
margin: 60px auto 0px;
}
@media ( max-width: 500px ) {
.colReverse {
flex-direction: column-reverse;
}
.border::after {
order: -1;
}
}
<div class="colReverse border">
<div>Item 1</div>
<div>Item 2</div>
</div>
jsFiddle 演示
推荐阅读
- javascript - Component.html:151 错误错误:InvalidPipeArgument:'无法将“14-05-2021”转换为管道'DatePipe'的日期'
- pytorch - RuntimeError: CUDA error: invalid argument torch tensor.cuda() 在执行编译的 C++ cuda 函数后引发错误
- javascript - 有什么方法可以禁用 Javascript 上的 LookUp (Dictionary, Thesaurus) Mac 功能?
- python - 如何将熊猫正确编码为 excel 文件
- r - 根据给定列表排序数据集
- git - 将更改拉入空存储库时会调用什么 Git 挂钩?
- python - 如何在matplot中绘制箭头指向表格内的单元格
- java - 如何在 Java 9+ 上运行 JUnit 5 测试,省略“public”修饰符?
- c# - MassTransit - 从请求响应中获取响应正常,但从跳过的队列中添加和删除消息?
- python-3.x - 在 SUMO 中设置最大车辆数量的正确方法是什么?