html - CSS定位/颜色

标签 html css positioning

我想要一个全灰色的背景,里面有一个较小的蓝色背景。

有点像

<body>
<div id= "background_1">
    <div id= "background_2">
    </div>
</div>
</body>

然后在css中

#background_1
{
background-color : gray;
z-index : 1;
}
#background_2
{
background-color : blue;
z-index : 2; 
}

谁能帮我解决这个问题?我知道它有点模糊,但我基本上想要一个全灰色的背景,前景中有一个较小的蓝色矩形。

最佳答案

您的代码一切正常...但不需要 z-index。

也许,将一些内容放入您的 div 中,或者固定它们的大小

编辑您的其他问题

// HTML
<body>
    <div id= "background">
    Test content
    </div>
</body>

// CCS
html,body
{
  margin:0 20px 0 20px;
  background-color : gray;
  height: 100%;
}
#background
{
  width:100%;
  height: auto !important; 
  height: 100%; 
  min-height: 100%; 
  background-color : blue;
}​

你可以在这里看到结果:http://jsfiddle.net/Nz5WK/1/

关于html - CSS定位/颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9338003/

相关文章:

javascript - 通过 Jquery 更改 CSS - 我的代码有什么问题?

JavaScript CSS 模态未显示正确的信息

html - 将鼠标悬停在 Chrome 中的图片上时,图片会消失

html - Bootstrap 3.0 : Full-Width Color Background, 中间的紧凑列

javascript - 在输入文本中添加图像

css - 我无法更改 <a> 的宽度而不使其 float 或阻塞

javascript - 图像 slider 问题

ios - 动态UIButton定位?

css - 将文本定位在画廊的中间,使其响应

html - div定位||为什么margin : property doesn't work yet the left: works?