代码之家  ›  专栏  ›  技术社区  ›  Boudhayan Dev

如何使用引导程序跨设备保留网格布局?

  •  1
  • Boudhayan Dev  · 技术社区  · 8 年前

    我正在使用Bootstrap v.3构建一个网站,它需要跨设备保持一致。我希望所有设备都保持相同的布局。我使用以下代码并排显示了两个youtube视频。

    <div class="row">
            <div class="col-md-7 col-lg-7 col-sm-7 col-xs-7" id="introduction">
                <p>The project uses Machine Learning to identify the waste items. A brief introduction about the Machine Learning technology is provided in the video below.
                </p>
                <iframe width="500" height="205" src="https://www.youtube.com/embed/yofjFQddwHE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe> 
            </div>
            <div class="col-md-5 col-lg-5 col-sm-5 col-xs-5">
    
                <iframe src="https://www.youtube.com/embed/7YgnJELpMyE?ecver=2" width="450" height="305" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
            </div>
        </div>
    

    该网站在桌面上看起来像这样-

    Desktop version

    然而,在手机上,它看起来是这样的。

    Mobile phone

    正如您所看到的,布局发生了变化 col-md-* col-sm-* col-xs-* 值相同。请帮忙。

    1 回复  |  直到 8 年前
        1
  •  1
  •   tao    8 年前

    TwBs v4用户注意事项:替换 col-xs-* 具有 col-*


    原始答案 (TwBs v3):您的 col公司-* 课程适用性非常好。

    而引导是 移动优先 也就是说 col-xs-7 不需要 col-sm-7 ,则, col-md-7 或以上。

    您可以通过选择元素并查看其 边界矩形框 'es(大多数开发工具都会突出显示)。然而,这并没有停止 <iframe> 元素(已硬编码 width height 属性)溢出其父对象的宽度。如果要覆盖它,需要设置 宽度 100% :

    iframe {
      display: block;
      width: 100%;
    }
    

    看到它工作:

    iframe {
      display: block;
      width: 100%;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="container">
      <div class="row">
        <div class="col-xs-7" id="introduction">
          <p>The project uses Machine Learning to identify the waste items. A brief introduction about the Machine Learning technology is provided in the video below.
          </p>
          <iframe width="500" height="205" src="https://www.youtube.com/embed/yofjFQddwHE" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
        </div>
        <div class="col-xs-5">
          <iframe src="https://www.youtube.com/embed/7YgnJELpMyE?ecver=2" width="450" height="305" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
        </div>
      </div>
    </div>

    如果应用了它但不起作用,则意味着项目中更强的选择器会在这些属性上应用不同的CSS规则,给您留下两个选项:

    • 查找并禁用这些规则(您可以检查元素以查找当前应用于它的所有规则)
    • 在你的CSS中使用更强(更具体)的选择器(你可以在网上找到大量解释CSS特定性原则的资源-记住你的选择器越强,你以后就越难修改它。理想情况下,你应该始终使用最不具体的选择器来应用所需的规则,从而确保将来的任何MOD都很容易应用)。

    笔记 :很可能, iframe 选择器对于您的项目不够强。您可以使用 #id .class 或者,如果不想通过添加任何额外的类或ID来更改标记,可以使用否定来夸大其特殊性:

    iframe:not(#_):not(#_)` { /* css rules here */ }