Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 背景色重叠问题_Html_Css - Fatal编程技术网

Html 背景色重叠问题

Html 背景色重叠问题,html,css,Html,Css,我的背景有一个简单(但令人沮丧)的问题。我目前有一个静态的背景图像和我的内容空间的纯色。由于某种原因,内容颜色没有显示出来?我觉得我已经做了所有的事情来修复它,但没有掷骰子。有什么建议吗 body { margin-left:auto; margin-right:auto; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 1em; line-height: 1; backgro

我的背景有一个简单(但令人沮丧)的问题。我目前有一个静态的背景图像和我的内容空间的纯色。由于某种原因,内容颜色没有显示出来?我觉得我已经做了所有的事情来修复它,但没有掷骰子。有什么建议吗

body {
  margin-left:auto;
  margin-right:auto;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 1em;
  line-height: 1;
  background-image:url(../img/bglogo.jpg);
  background-attachment:fixed;
}
#contentcontainer { 
  max-width: 960px; 
  margin: 0 auto; 
  float: none; 
  padding-top: 0px;
  padding-left:10px;
  background-color: #fffdf8;
}

这里可以找到有问题的网站:

这是因为
#contentcontainer
(home、about等)的内容都是浮动的,您没有清除它。执行此操作时,父元素不会包装子元素。如果查看
#contentcontainer
的高度,您将看到它被设置为0

要解决此问题,需要清除浮动部分。最快的方法是在
#contentcontainer
中添加一个空div作为最后一个子元素,并使用css
清除:两者

<section id='contentcontainer'>
 <section id='home'>...</section>
 ...
 ...
 <div style='clear: both;'></div>
</section>

...
...
...

通常,如果您发现自己经常清除浮动,大多数人会创建一个clear或clearfix类,并且只使用div的类名,而不是使用内联css。

您使用浮动来并排定位div。因此,父div在填充时无法访问这些div的高度。这将使父div保持0px的高度,使其在页面上不可见


添加“溢出:自动;”你的#contentcontainer类,你应该都准备好了。

validator.w3.org还为你的HTML显示了17个单独的错误和7个警告,包括重复的部分和未关闭的元素,这可能会对你的CSS造成严重破坏,所以你可能也需要处理这些错误和警告。