屏幕上的中心网站背景?

问题描述:

我在很多网站上看到过这个诀窍,我想为自己的项目做好准备。
我有一个图像background.jpg这是非常大,只是为任何屏幕大小做好准备。
我希望将背景图像置于访问者的窗口*。
我的意思是,虽然滚动窗口内容将移动,但背景将保持原位 - 垂直居中和水平居中。屏幕上的中心网站背景?

顺便说一句,大多数观众将有旧的蹩脚PC,所以它最好不闪烁,如果它会是JS。

body 
{ 
    background-image: url('background.jpg'); 
    background-repeat: no-repeat; /* you know... don't repeat... */ 
    background-position: center center; /*center the background */ 
    background-attachment: fixed; /*don't scroll with content */ 
} 
+0

完美!有用! – Vercas 2011-03-28 14:20:16

尝试的是在这个提琴:http://jsfiddle.net/maniator/3RRYe/3/
demo
看是否适合雅^ _^

+0

这应该仅仅是中心,而不是顶部* - 他要垂直居中了。 – Tesserex 2011-03-28 14:15:34

+0

'body { \t background:url(background.jpg)no-repeat center top; }'不工作' – Vercas 2011-03-28 14:15:53

+0

@Vercas,什么没有工作呢? – Neal 2011-03-28 14:16:25

把你的形象在身上背景:

body{ background-image:url('your/image/url'); } 

,并把身体内的div:

<body><div class="div-body">{your site's contents}</div></body> 

,并创建一个CSS选择器这样的:

.div-body{ 
    overflow:scroll; 
    width: 100%; 
    height: 100%; 
    display: block; 
    float: left; 
}