html - Bootstrap - 移动下一个在以前的中小型设备之上
问题描述
div
我有以下内容Bootstrap
:
<div class="card-header py-md-0 py-lg-0 py-xl-0 pl-0 pr-0">
<div class="d-flex justify-content-between align-items-center">
<div class="h5 mb-0">Text text</div>
<div class="text-right">
<div class="actions">
<a href="#" class="action-item"><i
class="far fa-heart mr-1"></i>
50</a>
<a href="#" class="action-item"><i class="far fa-eye mr-1"></i>
250</a>
</div>
</div>
</div>
<p class="font-size-1">Text text text text text
</p>
</div>
在中小型设备上,我希望第二个div
必须class="actions"
放在第一个之上并左对齐。
到目前为止,我已经尝试做类似下面的事情,但它不起作用。我缺少的东西:
@media only screen and (max-width: 960px) {
.col-xs-12 {
display: flex;
flex-direction: column-reverse;
}
}
一些技巧?谢谢
解决方案
假设您使用的是 Bootstrap 4:
Bootstrap 是为移动优先而构建的,因此最简单的解决方案是从.sm
视图中按顺序排列代码,这将是div
您想要的第一个作为整个.row
.
这是 Bootstrap 4 中的部分内容:https ://getbootstrap.com/docs/4.4/layout/grid/#order-classes
您必须添加.order-lg-2
到div
您想首先在屏幕sm
上显示的内容md
(请记住,首先是移动设备)。您还可以使用 Bootstrap 类之类的东西.justify-content-[sm, md, lg]-[start, center, between, end, around]
来设置它的位置。您可能还必须添加.d-flex
到第二个div
(这就是我在项目中的全部工作方式)。
这是我使用的有效示例(这些部分是并排的lg+
,因此您的列大小可能需要调整):
<div class="container">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-12 col-sm-12 order-lg-2 justify-content-center justify-content-sm-start"> <!-- shows first on sm/md, 2nd on lg -->
<!-- your code -->
</div>
<div class="col-xl-8 col-lg-8 col-md-12 col-sm-12 order-lg-1 justify-content-center justify-content-md-start"> <!-- shows 2nd on sm/md, 1st on lg -->
<!-- more code -->
</div>
</div>
</div>
这是我设置的一个快速 CodePen,向您展示它是如何工作的: Codepen
推荐阅读
- azure - Azure 数据工厂的逻辑应用连接器未显示现有工厂管道
- mysql - MySQL - 如何根据每年的总和获得最受欢迎的名称?
- python - ErlangC Python 函数
- sql - 使用 SQL 中的连接进行更新不适用于所有行
- android-studio - andriod studio插入空的imageview
- flutter - 使用 Switch (Flutter) 切换文本小部件
- go - 从 goroutine 之外停止 goroutine
- python - ValueError:需要至少一个数组与 sklearn cross_val_predict 方法连接
- python - Django 模型管理器未按预期工作
- python - 无法编组响应:键必须是 str、int、float、bool 或 None,而不是类型