2013-04-02 127 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

它實際上並沒有,我知道這個屬性,但使用這個,整個對齊得到改變 –

相關問題