【问题标题】:Bootstrap grid systems differentiate sizes in 2 types of screen sizesBootstrap 网格系统区分 2 种屏幕尺寸
【发布时间】:2020-09-15 17:35:23
【问题描述】:

我目前很好奇如何区分我的 BS 3 网格在 桌面尺寸(更宽的屏幕)笔记本电脑尺寸(更小的屏幕)。例如,目前我在容器中心有一个盒子形式,如下所示:

<div className="col-md-8 col-md-offset-2 col-sm-12 col-xs-12">
  ...
</div>

桌面(更宽的屏幕)中看起来不错,它位于中间,左右空间相同。但是,如何让它在笔记本电脑(小屏幕)中左右两边没有空间显得满了(col-md-12)?如果我在两个设备中检查devtools 上的元素,它们都被置于BS 的media querycol-md 条件下,因此较小的设备将继续获得col-md-8 col-md-offset-2 col-sm-12 col-xs-12 classes

【问题讨论】:

    标签: css twitter-bootstrap-3 media-queries


    【解决方案1】:

    网格断点基于最小宽度媒体查询,这意味着 它们适用于该断点及其以上的所有断点(例如,.col-sm-4 适用于小型、中型、大型和超大型设备, 但不是第一个 xs 断点)

    您可以组合这些类以获得每种屏幕尺寸所需的结果。

    EDIT :更改了 sn-p 并添加了一个完整的代码,可以达到预期的结果 -

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Example</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    </head>
    <body>
    
    
      <div class="row bg-danger" style = "height:200px;">
        <div class="col-md-0 col-lg-2"></div> <!--This will leave correct space on the sides of screen according to screen size-->
        <div class="col-md-12 col-lg-8 bg-success text-center" style = "top:50px;height:50px;">
          Your box
        </div> <!--Consider this div to be your box-->
      </div>
    
    
    </body>
    </html>
    

    上面的代码sn -p会将div的大小设置为-

    • 8 个网格用于大型桌面屏幕(屏幕等于或大于 1200 像素宽)
    • 适用于尺寸为 md 的屏幕(适用于小型笔记本电脑 - 屏幕等于或 大于 992px 宽),它将为 div 分配 12 个网格。

    您可以根据不同的屏幕尺寸以类似的方式组合网格以达到所需的效果。

    希望这能解决您的问题!

    【讨论】:

    • 您好,谢谢您的回答。我用col-lg-8 col-md-12 col-md-offset-2 col-sm-12 col-xs-12 尝试过,但在我的笔记本电脑上,它看起来仍然得到col-lg-8 断点,而不是进入col-md-12
    • 它应该可以工作。你试过第二个代码 sn -p 吗?
    • 我刚刚尝试了第一个 sn-p,第二个不起作用,因为我使用的是 BS 3。顺便说一句,我的笔记本电脑的分辨率为 1230 x 1012px,屏幕尺寸为 13"。但我想做它显示为col-md-12 没有空格,空格应该只在桌面大小中可见。
    • @JustinusHermawan 我添加了一个完整的代码,它可以按照您的要求工作。我还添加了一些额外的属性来帮助您将其可视化。希望这能解决您的问题!
    • 嗨,这是我的案例pastebin.com/G4ew46F1,右侧的content 框在我的笔记本电脑屏幕上应该是12-grids,但keep 变成8-grids
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多