CSS 容器/背景不显示;其余布局工程

标签 css html background containers

这是我的问题,我会尽我最大的努力在这里阐明 -- 我有一个使用外部样式表以完整 CSS 布局的简单网站。 我有一个主容器,其中包含网站内容的所有元素;然而,除了保存实际页面文本的那个和 businessbox 之外,它们似乎都在工作。现在,它显示主要容器的背景颜色(绿色)而不是它应该的颜色(白色)。我敢肯定这是我忽略的简单事情,以后可能会踢自己,但我想我会要求第二双眼睛。

这是我得到的以及它应该是什么样子的。如果我在使用这个容器时遇到问题,希望对 3 个垂直列进行编程不会成为问题!

截图:

enter image description here

我的样式表(style.css):

@charset "UTF-8";
/* CSS Document */


body {
background: #88b488;
margin: 3%;
font-family: Arial, Helvetica, sans-serif;
}

#container {
background: #006200;
width: 1020px;
margin: 0 auto;
}

#header {
background-image: url(img/BS_header.jpg);
background-repeat:  no-repeat;
background-position:center;
width: 1020px;
height: 322px;
} 


<!-- MENU ITEMS -->
#menu {
background: #25235b;
width: 100%;
z-index: 2;
}

#menu ul, #menu ul ul {
list-style-type: none;
padding: 0;
margin: 0;
float: right;
margin-top: 15px;
margin-right: 5px;
}

#menu ul li{
padding: 5px;
position: relative;
float: left;
}

#menu ul a:link, #menu ul a:visited{
display: inline-block;
color: #ffffff;
width: 90px;
padding: 5px;
text-decoration: none;
font-size: 12px;
font-weight: bold;
text-align: center;
} 

#menu ul a:hover, #menu ul a:active {
background: #006100;
}

#menu ul ul {
position: absolute;
margin-top: -1px;
right: 0px;
white-space: nowrap;
visibility: hidden;
}

#menu ul li:hover ul li{
    visibility: visible;
    color: #ffffff;
    background-color: #afafaf;
    padding: 0px;
}

<!-- CONTENT -->
#cbox{
width: 1020px;
background-color: #ffffff;
background-image:url(img/content_grad.jpg);
background-repeat: repeat-x;
}

#businessbox {
background-color: #006200;
width: 620px;
height: auto;
border-top: 3px solid #afafaf;
margin-top: 30px;
padding: 10px;
margin: 30px auto 0px;
}

.businesstitle {
text-align:center;
font-size: 20px;
color: #ffffff;
text-transform: uppercase;
font-style:italic;
}

.businesstext {
color: #ffffff;
font-size: 14px;
}

#footer {
font-size: 10px;
text-transform: uppercase;
color: #fff;
text-align: center;
padding: 10px;
background: #006100;
}

我的 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 http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Buy Local</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

<div id="container">
<div id="header">
    <div id="menu">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About Us</a></li>
            <li><a href="#">Hot Deals</a></li>
            <li><a href="#">Sign Up!</a></li>
            <li><a href="#">Resources</a>
                <ul>
                <li><a href="#">Events</a></li>
                </ul>
            </li>
      </ul>
    </div> <!--end of menu-->
</div> <!--end of header-->

<div id="cbox">
    <div id="businessbox">
        <div class="businesstitle">Our BUSINESS OF THE MONTH:</div><br />
        <img src="#" width="150" height="90" style="float: left; padding-right: 10px;"/>
        <div class="businesstext">You could be our next title sponsor and get your business in the spotlight with logo, name, and short blurb about your business.</div>
    </div> <!--end of businessbox-->

</div> <!--end of cbox-->

<div id="footer">
    2013 &copy; Buy Local
</div><!--end of footer-->

</div><!--end of container-->

</body>
</html>

最佳答案

您的 CSS 中有 HTML 注释。浏览器正在跳过呈现它旁边的行,因此您的#cbox 和#menu 样式永远不会应用。删除 <!-- MENU ITEMS --><!-- CONTENT -->评论,这应该可以正常工作。

参见 this fiddle在行动中。

关于CSS 容器/背景不显示;其余布局工程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15395847/

相关文章:

jquery - 使用 jquery 动态更改移动内容 slider 宽度以进行纵向和横向

jquery - 虚拟键盘中断位置 :fixed elements in iOS

javascript - 如何使用JS同时淡入2张图片?

html - 让图像在图像的黑色背景上发光

安卓背景重复-y

html - IE 表格高度未拉伸(stretch)到最大可能

css - 无法设置 SVG 文本的最大宽度

jQuery - 如果点击 DIV 中的文本

css - 在 HTML 中围绕 body 创建一个白色 body

ios - 如何通过向上/向下滚动使 iOS 应用程序背景发生变化