简体   繁体   English

更改div bg颜色

[英]Change div bg color

i created a main div and split-ted into two css code 我创建了一个主div并拆分为两个CSS代码

#main { background-color:#FFFFFF; width:1000px;}
#left {  width:750px; float:left }
#right {  width:250px; float:right }

but background color does not changes , when i changed it to 但是当我将其更改为时,背景色不会改变

#main {  width:1000px;}
#left { background-color:#FFFFFF; width:750px; float:left }
#right { background-color:#000000; width:250px; float:right }

it works but when height changes it looks boring i want to change the background color of whole main div. 它可以工作,但是当高度改变时看起来很无聊,我想改变整个主要div的背景颜色。

what about if your main div gets a 如果您的主要div得到一个

#main {
    min-height:100px;
    max-height:100px;
}

it needs a height to display background-color 它需要一个高度才能显示背景色

if its not working show the html part please 如果无法正常显示html部分,请

Without the html this is just a guess, but I think your problem is that the div#main has a height of 0. This happens because the floating divs inside are no longer part of the document flow. 没有html,这只是一个猜测,但是我认为您的问题是div#main的高度为0。这是因为内部的div不再是文档流的一部分。 Try setting a height on the main div, this should fix it. 尝试在主div上设置高度,这应该可以解决。

Add following rule 添加以下规则

#main:after { content: " "; #main:after {content:“”; display: block; 显示:块; overflow: hidden; 溢出:隐藏; clear: both; 清楚的 height: 0; 高度:0; } }

It will clear floats and make the container as high as the highest column inside. 它将清除浮标并使容器与内部的最高列一样高。

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

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