在CSS中为边距添加颜色

时间:2012-06-20 23:43:50

标签: css

我正在使用此代码将固定宽度图像居中/定位为背景。我需要在填充浏览器窗口边距的图像周围添加颜色。我尝试过背景色,边框颜色......

因此,图像的宽度为1050px。如果浏览器窗口是1500px,我想让剩余区域变黑(例如)。我怎么能这样做?

#content {
    text-align: left;
    width: 1050px;
    height: 825px;
    margin: 0 auto;
    padding: 0px;
    background-image: url(file:///X|/CarFingers/tabback1_hor.png);
    background-repeat: no-repeat;
} 

body {
    font-family: Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: #333333;
    text-align: center;
}
<div id="content">
<body>

</body>
</div>

4 个答案:

答案 0 :(得分:7)

首先:将div INSIDE放在body。然后你可以像这样编辑你的身体背景:

body{
    background-color: black;
}

答案 1 :(得分:4)

您的HTML无效,您的div标记不应包含body标记。如果您将div放在body中,您应该只需设置body的背景颜色。

答案 2 :(得分:1)

#content {
    text-align: left;
    width: 1050px;
    height: 825px;
    margin: 0 auto;
    padding: 0px;
    background-image: url('file:///X|/CarFingers/tabback1_hor.png');
    background-repeat: no-repeat;
} 

body {
    font-family: Helvetica, Arial, sans-serif;
    font-size: 14px;
    color: #333333;
    text-align: center;
    background-color: #000;      /* Add this to your code */
}

在你的HTML中你应该做这样的事情:

<body>
   <div id="content">
   </div>
</body>

你永远不应该把BODY包含在DIV中

答案 3 :(得分:0)

如果您想知道如何在CSS中为边框着色,那么

border: 10x solid #000;

border-width: 10px;
border-color: #000;
border-style: solid;
相关问题