【问题标题】:Bootstrap grid displaying column out of row in small screen引导网格在小屏幕中显示列外
【发布时间】:2020-08-09 00:09:51
【问题描述】:

如何在Hello-div-3之后以小屏显示我的Hello-div-2? 现在的流程是

Hello-div-1、Hello-div-2、Hello-div-3、Hello-div-4

应该是

Hello-div-1、Hello-div-3、Hello-div-2、Hello-div-4。

<div class="container">
    <div class="row">
        <div class="col-md-8 col-12 bg-primary">
            <h2 class="font-weight-light">Hello-div-1</h2>
        </div>
         <div class="col-md-4 col-12 bg-success">
            <h2 class="font-weight-light ">Hello-div-2</h2>
        </div>
    </div>
     <div class="row">
         <div class="col-md-8 col-12 bg-info">
            <h2 class="font-weight-light">Hello-div-3</h2>
        </div>
         <div class="col-md-4 col-12 bg-warning">
            <h2 class="font-weight-light">Hello-div-4</h2>
        </div>
    </div>
</div>

【问题讨论】:

    标签: css bootstrap-4 grid


    【解决方案1】:

    将它们全部放在同一个.row 中并使用.order- 类...

    <div class="container">
        <div class="row">
            <div class="col-md-8 col-12 bg-primary order-0 order-md-0">
                <h2 class="font-weight-light">Hello-div-1</h2>
            </div>
            <div class="col-md-4 col-12 bg-success order-2 order-md-0">
                <h2 class="font-weight-light ">Hello-div-2</h2>
            </div>
            <div class="col-md-8 col-12 bg-info order-1 order-md-0">
                <h2 class="font-weight-light">Hello-div-3</h2>
            </div>
            <div class="col-md-4 col-12 bg-warning order-3 order-md-0">
                <h2 class="font-weight-light">Hello-div-4</h2>
            </div>
        </div>
    </div>
    

    https://codeply.com/p/m8sgEDDmp2

    【讨论】:

    • 感谢@Codeply-er,该行应该保持原样。这可以使用一些媒体查询来完成吗?
    • 没有。您不能更改共享不同 flexbox 父级 (.row) 的列的顺序。为什么它们需要位于不同的行中?
    【解决方案2】:

    如果你不能改变结构,我能想到的唯一解决方案是

    <div class="container">
        <div class="row">
            <div class="col-md-8 col-12 bg-primary">
                <h2 class="font-weight-light">Hello-div-1</h2>
            </div>
             <!-- hide this in small screen -->
             <div class="col-md-4 col-12 bg-success">
                <h2 class="font-weight-light ">Hello-div-2</h2>
            </div>
        </div>
         <div class="row">
             <div class="col-md-8 col-12 bg-info">
                <h2 class="font-weight-light">Hello-div-3</h2>
            </div>
            <!-- show this in small screen -->
             <div class="col-md-4 col-12 bg-success">
                <h2 class="font-weight-light ">Hello-div-2</h2>
            </div>
             <div class="col-md-4 col-12 bg-warning">
                <h2 class="font-weight-light">Hello-div-4</h2>
            </div>
        </div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2015-12-07
      • 2021-02-09
      • 2017-02-12
      • 1970-01-01
      • 2021-06-15
      • 2013-12-09
      相关资源
      最近更新 更多