如何用背景颜色填充整个div

时间:2016-06-24 16:19:12

标签: html css twitter-bootstrap twitter-bootstrap-3

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

这是fiddle

我知道我错过了一些非常明显的东西,但是如何让黄色填满整个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>

3 个答案:

答案 0 :(得分:3)

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

所以将.container更改为.container-fluid

bootstrap docs

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

.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>

答案 1 :(得分:0)

或只是:

.yellow {
    background-color: yellow;
    padding: 0 0;
}

答案 2 :(得分:0)

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

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

相关问题