CSS背景颜色不能正常工作 [英] CSS background color not working properly

查看:63
本文介绍了CSS背景颜色不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好吧


i是一个新人..我试图使用以下代码创建一个小网站:

Good afternoon

i am a newbe.. I have tried to create a small site with the following code:


<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

< html xmlns =" http://www.w3.org / 1999 / xhtml">


< head>

< meta content =" en-us" HTTP的当量= QUOT;内容语言与QUOT; />

< meta content =" text / html;字符集= UTF-8英寸HTTP的当量= QUOT;内容类型" />

< style type =" text / css">

#page {

background-color:#FFFFFF;

margin-right:auto;

margin-left:auto;

border:2px solid#008000;

font-family:Gabriola,Lucida Sans,Lucida Sans Regular,Lucida Grande,Lucida Sans Unicode,Geneva,Verdana,sans-serif;

宽度:97%;

身高:自动;

最大宽度:1200px;

}

#banner {

背景色:#3366FF;

宽度:100%;

身高:150px;

}

#body {

宽度:100%;

身高:自动;

margin-top:10px; < br $>
}

#leftnavpanel {

float:left;

宽度:20%;

background-color:#008000;

margin-top:2px;

margin-right:1px;

margin-bottom:2px ;

填充左:10px;

}

#conten t {

宽度:78%;

身高:汽车;

浮动:正确;

边框:薄固体#00FF00;

background-image:none;

}

< / style>

< / head>


< body style =" background-color:#8B8878">

< div id =" page">

< div id =" banner">< / div>

< div id =" body">

< div id =" leftnavpanel"> asdasd< br />

asd< br />

< / div>

< div id =" content"> asdasd< br />

asd< br />

< / div>

< / div>

< / div>

< / body>

< / html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
#page {
background-color: #FFFFFF;
margin-right: auto;
margin-left: auto;
border: 2px solid #008000;
font-family: Gabriola, "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
width: 97%;
height:auto;
max-width: 1200px;
}
#banner {
background-color: #3366FF;
width: 100%;
height: 150px;
}
#body {
width: 100%;
height: auto;
margin-top: 10px;
}
#leftnavpanel {
float: left;
width: 20%;
background-color: #008000;
margin-top: 2px;
margin-right: 1px;
margin-bottom: 2px;
padding-left: 10px;
}
#content {
width: 78%;
height: auto;
float: right;
border: thin solid #00FF00;
background-image: none;
}
</style>
</head>

<body style="background-color: #8B8878">
<div id="page">
<div id="banner"></div>
<div id="body">
<div id="leftnavpanel">asdasd<br />
asd<br />
</div>
<div id="content">asdasd<br />
asd<br />
</div>
</div>
</div>
</body>
</html>



但是,我遇到的问题是因为在上层元素-div页面中给出的颜色白色[ffffff] - 无法正常工作。较低的div不会将颜色变为白色作为背景,而是它们正在获得defaut body标签颜色。更多的过度表达网络在工作区域完美地展示了这一点,但是当进入IE和Mozilla预览时它就失败了。


你能帮我吗?



However, the problem that I am facing is because the color white [ffffff] that was given in upper element -div page - is not working properly. the lowers divs are not getting the color white as background, in stead they are getting the defaut body tag color. and more over expression web is displaying this perfectly in work area, but when comes to IE and Mozilla preview it is failing.

Could you please help me.

附加文件
previews.zip (36.0 KB,106 views)
Attached Files
previews.zip (36.0 KB, 106 views)

推荐答案

我猜它是因为它浮动(并且父元素不够伸展)
I guess it?s because it?s floated (and the parent element does not stretch wide enough)


感谢您回复Dormilich,但是,我希望最后一个div浮动,否则这个div会从一个人那里下来。我们可以通过使用表来解决这个问题,但是,我不想使用表格,你/我可以请求解决方案。


非常感谢。
Thank you for the reply Dormilich, however, I want the last div to float right else this div would come down the berfore one. We can solve this by using table, however, i prefer not to use table, could you/anyone please advice on a solution.

Thank you very much.


为什么不手动定义颜色?
why don?t you define the colour manually?


这篇关于CSS背景颜色不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆