HTML 和 BODY 不同的背景

标签 html css

我想在整个 HTML 文档中使用渐变,并且在 BODY 标记的中心我需要另一个居中的背景。

编辑看看它失败了多少试试看:

http://xn--wiadomesny-37b.pl/bg

这张图片说明了这一点:

enter image description here

如果我放入 CSS,它会失败,甚至只显示 1 个背景,如果下面应该显示 repeat-y 背景:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
html {
    background-color: #ffeacd;
    background-image: url(bg.png);
    background-repeat: repeat-x;
}
body {
    background-image: url(bg_overlay.png);
    background-repeat: no-repeat;
    background-position: center;
}
.content {
    width:1020px;
    padding: 0px;
    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
}
</style>
</head>
<body>
<div class="content">
  <p>This content is closed in 1020px wide DIV, as to merge in most displays. </p>
  <p>Rest around is an background seen or unseen depends on users screen size. </p>
  <p>Me got 24'' so its obvious that I will see all backgrounds and even gradients as 
    blank space fillers</p>
  <p>
  <h1>See how much it fails in various browsers:</h1>
  <ul>
    <li><a href="chrome.png">Chrome</a></li>
    <li><a href="ff.png">Firefox</a></li>
    <li><a href="ie.png">IE</a></li>
  </ul>
  </p>
  )</div>
</body>
</html>

最佳答案

如果您没有看到两个背景,那可能是因为您的 body 元素与 html 占据了相同的区域。

下面演示了元素可以有不同的背景(http://jsfiddle.net/ZVHqs/):

<!doctype html>
<style>
html { background: green; }
body { background: yellow; margin: 1em; }
</style>
Hello world

关于HTML 和 BODY 不同的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10480225/

相关文章:

html - 在同一行显示 Canvas

css - Firefox CSS3 等腰三 Angular 形渲染问题

html - 如何防止输入字段将最后一个元素推到 div 之外?

javascript - 动态加载javascript失败,但innerHTML却失败

jquery - 如何将每个单词包装在一个范围内但保留文本格式

javascript - <td><span>course</span>English</td> 如何获取TD值NOT span值

html - 如何在 Angular 2 的 ngmodel 上使用二维数组?

html - 停止覆盖 CSS 属性

c# - 如果文本超过三行,如何截断文本?

javascript - 使用 CSS 定位 .slick-current 幻灯片两侧的第一个元素