如何用背景颜色填充整个div [英] How to fill entire div with background color

查看:33
本文介绍了如何用背景颜色填充整个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是一个小提琴.

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

.new-section {高度:100%;填充顶部:150px;文本对齐:居中;背景:#eee;}.黄色 {背景颜色:黄色;}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="样式表"/><section id="new" class="new-section"><div class="容器"><div class="row"><div class="col-lg-6"><h1>左侧部分</h1>

<div class="col-lg-6 Yellow"><h1>部分右侧</h1>

</section>

解决方案

发生这种情况是因为您将 .col-lg-*.container 一起使用,它只有宽度:1170px

所以将 .container 改为 .container-fluid

引导程序文档

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

.new-section {高度:100%;填充顶部:150px;文本对齐:居中;背景:#eee;}.黄色 {背景颜色:黄色;}

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="样式表"/><!-- 新展区--><section id="new" class="new-section"><div class="container-fluid"><div class="row"><div class="col-xs-6 col-lg-6"><h1>左侧部分</h1>

<div class="col-xs-6 col-lg-6 Yellow"><h1>部分右侧</h1>

</section>

I'm trying to get a background color to fill the entire div in a child div in bootstrap, but I'm completely stuck. I want the right section to be yellow, but it's only highlighting the text in the div.

Here's a fiddle.

I know I'm missing something really obvious, but how do I get yellow to fill the entire 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>

解决方案

This is happening because you are using .col-lg-* with .container which only has width:1170px

So change .container to .container-fluid

See more info about containers in 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>

这篇关于如何用背景颜色填充整个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆