如何用背景色填充整个div

新手上路,请多包涵

我正在尝试获取背景颜色以填充引导程序中子 div 中的整个 div,但我完全卡住了。我希望右边的部分是黄色的,但它只是突出显示了 div 中的文本。

这是一个 小提琴

我知道我遗漏了一些非常明显的东西,但是如何让黄色填充整个 col-lg-6 div?

 .new-section {
  height: 100%;
  padding-top: 150px;
  text-align: center;
  background: #eee;
}

.yellow {
  background-color: yellow;
}
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<section id="new" class="new-section">
  <div class="container">
    <div class="row">
      <div class="col-lg-6">
        <h1>Section left</h1>
      </div>
      <div class="col-lg-6 yellow">
        <h1>Section right</h1>
      </div>
    </div>
  </div>
</section>

原文由 hcgriggs 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 430
2 个回答

发生这种情况是因为您正在使用 .col-lg-*.container 只有 width:1170px

所以改变 .container.container-fluid

bootstrap 文档 中查看有关容器的更多信息

 .new-section {
  height: 100%;
  padding-top: 150px;
  text-align: center;
  background: #eee;
}
.yellow {
  background-color: yellow;
}
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<!-- New Exhibit Section -->
<section id="new" class="new-section">
  <div class="container-fluid">
    <div class="row">
      <div class="col-xs-6 col-lg-6">
        <h1>Section left</h1>
      </div>

      <div class="col-xs-6 col-lg-6 yellow">
        <h1>Section right</h1>
      </div>
    </div>
  </div>
</section>

原文由 dippas 发布,翻译遵循 CC BY-SA 3.0 许可协议

请记住 h1 的顶部和底部边距将由其包装器接管,并且 不会 受到背景颜色的影响,因为它们位于块元素之外。您可以删除 h1 标签并以类似的方式设置父容器的样式(但使用填充而不是边距):

https://jsfiddle.net/j33wz2o6/1/

原文由 Johannes 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题