背景颜色' div' div不工作

时间:2016-02-02 19:34:46

标签: html css

尝试为包含图像的div的背景着色,只有将我的页脚封装在我不想要的div中才能成功。我只想将背景颜色应用于div中的部分。



/* CSS */

    div#gallery_contain {
       width: 850px;
       margin: 0 auto;
       padding: 0 5%;
       background-color: #1a75ff;
    }

      footer {
       clear: both;
       text-align: center;
    }

 <div id="gallery_contain">
        <section>
        </section>
    </div>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

您需要在css中have some content in your divspecify height explicitly让div显示背景。

答案 1 :(得分:0)

因为您的图库容器没有高度,所以背景不会显示。如果在DIV上设置高度或向DIV添加内容,则会显示背景颜色。

div#gallery_contain {
   width: 850px;
   min-height: 100px;
   margin: 0 auto;
   padding: 0 5%;
   background-color: #1a75ff;
}

footer {
  clear: both;
  text-align: center;
}

OR

<div id="gallery_contain">
    <section>
         This is the gallery.
    </section>
</div>

答案 2 :(得分:0)

您可以使用display:block;。或者,当有一些内容时,您可以应用此height:auto; width:auto;

相关问题