简体   繁体   English

为什么我的背景色结束了?

[英]Why does my background colour end?

I am creating a footer for a webpage and for some reason, I can't get the background colour to fill the whole div once I start populating it. 我正在为网页创建页脚,由于某种原因,一旦开始填充,就无法获得背景色来填充整个div。

EXAMPLE

.widefooter {
    background-color:#EFEFEF;
    width:100%;
    font-size:12px;
}

After I add the "links" under the <hr> the background colour of the footer just ends, even though the links are nested in the footer div, not after it. <hr>下添加“链接”后,页脚的背景颜色刚刚结束,即使链接嵌套在页脚div中也没有。

This is what I'm getting: 这就是我得到的:

在此处输入图片说明

This is what I want to achieve: 这是我要实现的目标:

在此处输入图片说明

Add overflow:hidden to .widefootercontent . 添加overflow:hidden.widefootercontent

Floated elements do not contribute to the parent container's height unless specifically done so with this overflow property. 浮动元素不会对父容器的高度产生影响,除非使用此overflow属性专门这样做。

It is the problem of floating elements. 这是浮动元素的问题。 which need to be cleared by a third element specially created for clearing floats. 需要通过专门为清除浮点数而创建的第三个元素来清除这些内容。

HTML HTML

<div class="parent">
   <div class="child"></div>
   <div class="child"></div>
   <div class="child"></div>
   <div class="clearFloat"></div>  <!-- for clearing above float elements -->
</div>

CSS CSS

.clearFloat {
    clear: both;
}

I always prefer adding a last child element to clear the floats instead of using overflow :hidden property because if the child element needs to be shown outside of the parent element using position: absolute then overflow: hidden will hide the child. 我总是更喜欢添加最后一个子元素来清除浮点数,而不是使用overflow :hidden属性,因为如果需要使用position:absolute来将子元素显示在父元素之外,那么overflow:hidden将隐藏子元素。 which is really frustrating in bigger projects. 在更大的项目中,这确实令人沮丧。

Working Fiddle 工作小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM