gpt4 book ai didi

html - 如何使用 Bootstrap 跨设备保留网格布局?

转载 作者:行者123 更新时间:2023-11-28 15:04:49 24 4
gpt4 key购买 nike

我正在使用 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-*,但布局发生了变化> 值相同。请帮忙。

最佳答案

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


原始答案(TwBs v3):您的 col-*类(class)适用得很好。

而 Bootstrap 是移动优先,这意味着 col-xs-7不需要 col-sm-7 , col-md-7或以上。

您可以通过选择元素并观察它们的bounding-rect-box(大多数开发工具都会突出显示)来检查它。然而,这并没有停止 <iframe>元素(已硬编码 widthheight 属性)溢出其父元素的宽度。如果你想覆盖它,你需要设置他们的 width100% :

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 特定性原则的在线资源 - 请记住,您的选择器越强大,您以后修改它的难度就越大。理想情况下应始终使用应用所需规则的最不具体的选择器,从而确保它们易于应用任何 future 的模组)。

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

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

关于html - 如何使用 Bootstrap 跨设备保留网格布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49638274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com