屏幕上的中心网站背景?
问题描述:
我在很多网站上看到过这个诀窍,我想为自己的项目做好准备。
我有一个图像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 */
}
答
把你的形象在身上背景:
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;
}
完美!有用! – Vercas 2011-03-28 14:20:16