【问题标题】:Bootstrap 4: how to change the order of a columns when the screen size changesBootstrap 4:当屏幕大小改变时如何改变列的顺序
【发布时间】:2018-09-14 11:41:46
【问题描述】:

我希望我的网站在 md 大小的屏幕上具有较大的屏幕,右侧是更大的手机,左侧是文本。但是一旦屏幕尺寸小于 md,我希望文字在手机下方。

<section id="" class="pt-3 mt-3">
    <div class="container">
      <div class="row">
        <div class="col-md-6 my-auto text-right">
          <h3 class="display-3 lato_text">Description</h3>
          <p class="lead">On the map, click on an OddJob to get a quick preview.</p>
          <p class="lead">In the preview, you will see the title and price of the job.</p>
        </div>
        <div class="col-md-6">
          <div class="text-center">
            <img id="phone-screenshot" src="img/JobFullDesc.jpg" class="img-fluid mb-3">
          </div>
        </div>

      </div>
    </div>
  </section>

我将如何更改我的 html 以使其在 md 大小的屏幕及以下屏幕上显示在手机下方。

【问题讨论】:

    标签: html bootstrap-4


    【解决方案1】:

    您可以使用 Bootstrap 4 的 order classes

    不幸的是,Bootstrap 4 的布局类是 mobile-first,因此您需要指定默认情况下文本应位于图像之后,并覆盖 这适用于大屏幕。

    要在中小型设备上将文本放在图像下方,您需要为文本指定 order-2order-md-1 类,并为图像指定 order-1order-md-2 类。

    这可以在下面看到:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    
    <section id="" class="pt-3 mt-3">
      <div class="container">
        <div class="row">
          <div class="col-md-6 my-auto text-right order-2 order-md-1">
            <h3 class="display-3 lato_text">Description</h3>
            <p class="lead">On the map, click on an OddJob to get a quick preview.</p>
            <p class="lead">In the preview, you will see the title and price of the job.</p>
          </div>
          <div class="col-md-6 order-1 order-md-2">
            <div class="text-center">
              <img id="phone-screenshot" src="http://placehold.it/100" class="img-fluid mb-3">
            </div>
          </div>
        </div>
      </div>
    </section>

    请注意,在小屏幕上(例如在默认视图中使用这个 sn-p),图像出现在文本之前,但在大屏幕上(例如在Full page 视图中使用这个 sn-p)图像出现在文本之前在正文之后。

    【讨论】:

    • 我尝试添加 order-md-2(和 1),但它似乎相反。所以在 md 以上的大小上,img 在左边,文本在右边。而对于 sm,它将是顶部的文本和底部的 img。
    • @TamirOffen -- 你把课程弄错了。 order-2 order-md-1 在描述上,order-1 order-md-2 在图像上:)
    • Bootstrap 4 布局类移动优先是这里真正的问题。谢谢。
    猜你喜欢
    • 2014-10-09
    • 1970-01-01
    • 2017-09-02
    • 2021-07-13
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-09-13
    相关资源
    最近更新 更多