2013-04-02 65 views
0

当我调整窗口大小时,背景图像也会移动并被调整大小,我不希望它调整大小,我希望它保持静态。我真的很困惑如何保持我的背景静态。 如果我设置像素宽度,那么它仍然是静态的,但是这不会是很好的选择,因为根据不同的屏幕尺寸上不要在窗口上移动背景图像调整大小,保持静态

body { 
    background-color: #000000; 
    margin: 0 auto; 
    width: 100%; 
} 

#container { 
    background: url("url") no-repeat scroll center top transparent; 
    width: 100%; 
} 

的代码是这样的:

<body> 
<div id="container"> 
</div> 
</body> 

回答

1

你尝试呢?

#container { 
    background: url("url"); 
    background-repeat:no-repeat; 
    background-position:fixed; 
} 
+0

图像被对准的权利,但是静态的东西被解决 –

+1

喜你尝试,而不是'背景位置:固定;'试试这个'背景位置:center top;' – jhunlio

+2

背景位置没有'fixed'值。 – sglessard

0

如果设置图像是width:100%然后图像会与屏幕调整。如果您希望它只坐在顶部中心而不缩放,则可以使用position:fixed,显式width,然后正确放置它。

#container { 
    background:url("url") no-repeat scroll center top transparent; 
    background-position:fixed; 
    position:fixed; 
    width:500px; /* width of image */ 
    height:auto; 
    top:0; 
    left:50%; 
    margin-left:-250px; /* -1/2 width */ 
} 
1

试试这个代码 -

#container { 
    background: transparent url("url") 0 0 no-repeat; 
    width: 100%; 
} 
+1

图像现在对齐,但是是静态的东西得到解决 –

+0

如果这解决了您的问题,然后请接受并upvote。 – Ashis

+0

它实际上并没有,我知道这个属性,但使用这个,整个对齐得到改变 –

相关问题