2013-02-06 146 views
0

我想,所以我用下面的代碼全屏背景HTML

HTML顯示圖片作爲我的網站的背景:

<div> 
    <img src="images/background.jpg" id="bg" alt="background_image" /> 
</div> 

的CSS:

#bg { 
    width: 100%; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 
} 

我想知道如何限制背景的大小,因爲我不想伸展超過2000像素。

感謝

+0

背景大小是一個選項使用。 詳情請參閱http://www.css3.info/preview/background-size/ – lukeocom

回答

1

只需在您的CSS最大寬度。

#bg { 
    width: 100%; 
    max-width: 2000px; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 
} 
0

您可以使用max-width

#bg { 
    width: 100%; 
    height: 75%; 
    position: absolute; 
    z-index: -5000; 

    max-width: 2000px; /* use this to limit the maximum width */ 
} 
1

我會用下面的CSS:

html { 
    background: url(images/bg.jpg) no-repeat center center fixed; 

    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
} 

和完全刪除您的股利。

要限制大小,您可以:

#bg { 
    min-height: 100%; 
    max-width: 2000px; 
    width: 100%; 
    height: auto; 
    position: fixed; 
    top: 0; 
    bottom: 0; 
} 
0

我沒有測試過,但增加max-width:2000px;您#bg選擇。

0

試試這個

#bg { 
width: 100%; 
height: 100%%; 
background-size:100%; 
}