img表现得像背景img?

use*_*630 9 html css

我在页面上有一个物理图像..

<img src="image.png" alt="image-name" />
Run Code Online (Sandbox Code Playgroud)

我希望它表现得好像它是身体背景图像虽然..

body{
background: url(image.png) no-repeat center top;
}
Run Code Online (Sandbox Code Playgroud)

即在没有浏览器看到它的情况下居中,所以如果浏览器更宽,那么没有滚动条等?

这可能吗?

lui*_*s90 1

position: fixed; z-index: -5000你想要的吗?

position: fixed使图像始终固定在浏览器上的某个位置,无论内容如何。

z-index: -5000只是把图像放在一切后面

为了使其居中,我认为您需要事先知道图像的大小。如果这样做,请添加

top: 50%; 
left: 50%;
margin-top: -100px;
margin-left: -250px;
Run Code Online (Sandbox Code Playgroud)

其中 100 是图像高度的一半,250 是图像宽度的一半。从中心位置获取 :固定元素

演示: http: //jsfiddle.net/SPsRd/1/