html - CSS body 固定背景

标签 html css background-image

我有这个 CSS:

body
{
    background-position: center top;
    background-color: rgb(237, 237, 237);
    font-size: .85em;
    font-family: "Trebuchet MS" , Verdana, Helvetica, Sans-Serif;
    margin: 0px auto;
    padding: 0;
    color: #696969;
    width: 1000px;
    height: 1200px;
    background-image: url('Background.png');
    background-repeat: no-repeat;
    background-attachment: inherit;    
    top: 0px;
}

当我最大化窗口时一切正常,但是当我缩小窗口时,背景图像会移动。

This is how look in maximizedbrowser window

And this is after change window size

最佳答案

您从人们那里得到的大多数答案都需要 IE9+(因为它是 CSS3)。但是,如果您希望用户也使用较旧的浏览器(我在这里是务实和安全的),我认为您需要使用 jQuery/JavaScript 来做到这一点。过去我在 CSS3 中做过类似的事情,但后来我意识到大多数公司/公司仍在使用 IE8,而最好的方法是使用 JavaScript。

这里有几个例子:

  1. http://buildinternet.com/project/supersized/slideshow/3.2/demo.html (这是一个很好的例子)
  2. http://designshack.net/?p=13616
  3. http://css-tricks.com/examples/FullPageBackgroundImage/jquery.php

关于html - CSS body 固定背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11195605/

相关文章:

css - 用图像覆盖整个 div

HTML & CSS : Text in one line with span align right full visible

html - #services div 有内容但显示为空 div

javascript - 如何垂直显示一组动态生成的按钮

javascript - HTML5 Canvas 中的超高分辨率图像

html - CSS | Div 背景图片

php - 使用 PHP 将 HTML 一分为二

html - 为什么使用额外的 CSS 类来替换 H5 类会更好?

css - 如何去除手机网站的背景图片?

css sprite 图像位置