1

我正在使用 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>

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

桌面版

但是,在手机上,它看起来像这样。

移动电话

如您所见,尽管具有col-md-* col-sm-*col-xs-*值相同,但布局会发生变化。请帮忙。

4

1 回答 1

1

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


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

而且 Bootstrap 是移动优先的,这意味着col-xs-7不需要col-sm-7col-md-7或更高版本。

You can check it by selecting the elements and watching their bounding-rect-box'es (which are highlighted by most dev-tools). However, this doesn't stop <iframe> elements (which have hardcoded width and height properties) to overflow the widths of their parents. If you want to override that, you need to set their width to 100%:

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

See it working:

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>

If you apply it and it doesn't work, it means different CSS rules are applied on those properties by stronger selectors in your project, leaving you two options:

  • find and disable those rules (you can inspect element to find all rules currently applying to it)
  • 在你的 CSS 中使用更强大(更具体)的选择器(你可以找到大量解释 CSS 特异性原则的在线资源 - 请记住,你的选择器越强大,你以后修改它的难度就越大。理想情况下,应该始终使用应用所需规则的最不具体的选择器,从而确保它们易于应用任何未来的模块)。

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

iframe:not(#_):not(#_)` { /* css rules here */ }
于 2018-04-03T20:50:24.160 回答