【问题标题】:Setting 100% width of view-port in bootstrap 4.5在引导程序 4.5 中设置 100% 的视口宽度
【发布时间】:2020-08-10 02:05:14
【问题描述】:

我正在尝试在容器中使用 class='row' 获得 100% 的宽度

HTML 结构:

<div class="container"><!-- this is main container holding overall contents dont want to remove it -->
    <div class='row w-100 bg-dark' id='heading'>
      <h2>some headings</h2>
    </div>
    <article></article>
    <aside></aside>
    <footer></footer>
</div>

id='heading' 的行没有扩展到 100% 宽度,因为它在容器类中,我使用了布局实用程序 w-100,但它不起作用。

如何强制此 div 扩展至 100% 但仍保留在容器中?

【问题讨论】:

  • yup 容器是问题所在,请改用container-fluid,如果您不希望列之间有间距,请在row 上添加no-gutters,至少一个列应该是row 的子级你有 -15px 这将导致水平滚动条错误
  • 会影响整个版面!我只是想让#heading 成为 100% 而不是其他区域。

标签: bootstrap-4


【解决方案1】:

试试这个,将两者分开并在container-fluid中添加标题

<article>
  <div class="container-fluid">
    <div class="row no-gutters" id="heading">
      <div class="col">
        <h2>some headings</h2>
      </div>
    </div>
  </div>
  <div class="container">
    <article></article>
    <aside></aside>
    <footer></footer>
  </div>
</article>

article 只是一个包装,所以你可以看到。


编辑:

使用绝对定位从容器中拉出标题,不理想,可能会导致其他问题,但它是一种选择

.container {
  display: block;
  width: 100%;
  max-width: 200px;
  background-color: red;
  margin: 0 auto;
}

article {
  margin-top: 65px
}

#heading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  background-color:green;
}
<div class="container">
  <div id='heading'>
    <h2>some headings</h2>
  </div>
  <article>Lorum ipsum</article>
  <aside>Lorum ipsum</aside>
  <footer>Lorum ipsum</footer>
</div>

【讨论】:

  • 亲爱的劳伦斯,问题是我不能移动容器类,无论如何它都会在那里,所以有什么办法可以覆盖父宽度并达到 100%?
  • 没有什么是一成不变的,尤其是模板,值得移动/重构它。 (去过那里),但您可能可以在#header 上使用绝对、固定或粘性定位之一,但这会带来其他问题,例如使其看起来像相对。
  • 实际上我只是在做 UI 部分,它是硬编码的。所以我想我必须重构它
  • 我添加了位置:绝对;作为一个例子,但并不理想。希望对你有帮助
  • 我会试一试并回复您。谢谢劳伦斯。
猜你喜欢
  • 2020-08-11
  • 2013-09-11
  • 2014-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-08
  • 1970-01-01
相关资源
最近更新 更多