css - 通过CSS更改显示顺序

标签 css mobile layout

我有一段基于 Bootstrap 的代码:

<div class="alert alert-primary" style="padding:0.6rem;margin-bottom:0.5rem">
  <div style="display:inline-block;font-weight:bold;width:100px;vertical-align:top">Name</div>
  <div style="display:inline-block;vertical-align:top">Summary, which is long and will wrap on small screen</div>
  <div style="display:inline-block;float:right;vertical-align:top">Date</div>
</div>

在笔记本电脑屏幕上看起来像这样:

Name    Summary...            Date

在手机屏幕上看起来像:

Name
Summary...
                                                    Date

即日期在第 3 行,并从“警告”框的背景中弹出。

我希望它在手机屏幕上是这样的:

Name                                       Date
Summary, ....
... ...

即在大屏幕上:姓名、摘要、日期,在小屏幕上,姓名、日期、摘要

这可能吗

最佳答案

请试试这个代码

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>


@media(max-width: 767px){
  .alert.alert-primary{
    display: flex;
    flex-direction: column;
  }
  .alert div:nth-child(1){
    order: 1;
    display: block !important;
  }
  .alert div:nth-child(2){
    order: 3;
    display: block !important;
  }
  .alert div:nth-child(3){
    order: 2;
    display: block !important;
  }
}
</style>
</head>
<body>

<div class="alert alert-primary" style="padding:0.6rem;margin-bottom:0.5rem">
  <div style="display:inline-block;font-weight:bold;width:100px;vertical-align:top">Name</div>
  <div style="display:inline-block;vertical-align:top">Summary, which is long and will wrap on small screen</div>
  <div style="display:inline-block;float:right;vertical-align:top">Date</div>
</div>

</body>
</html>

关于css - 通过CSS更改显示顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55811930/

相关文章:

css - 尝试对齐 div 内的元素

css - 当子 div float 时,父 div 失去自动高度

html - 如何用备用样式表覆盖 main.css?

javascript - 自定义分页 swiper.js

mobile - Web View 中的 Paypal 结帐

mobile - XPath - 如何通过包含新行的@text 进行选择

java - 将 JScrollPane 的组件向左对齐?

ios - 当应用程序激活时,导航栏会调整大小

android - 使用按钮添加动态小部件

java - 相对布局 android Loopable