2014-10-28 75 views
-1

我想在我的html中使用背景圖片(bg.png),但我想調整圖片的大小,所以它會始終填充整個頁面。我這樣做是這樣的:如何調整body標記中的html背景圖片的大小

.stretch { 
width:100%; 
height:100%;} 

#background { 
width: 100%; 
height: 100%; 
position: fixed; 
left: 0px; 
top: 0px; 
z-index: -1; } 

身體裏面的:

<div id="background"> 
<img src="bg.png" class="stretch"> 
</div> 

所以我在網站上使用CMS(E107),現在,我要像在我的HTML的背景下,我改變了圖片,但我不知道如何在css/php文件中使用它。

這是它的主題的CSS:

body 
{ 
font-size: 12px; 
margin-top: 0px; 
margin-right: auto; 
margin-bottom: 0px; 
margin-left: auto; 
width: 87%; 
border-color: #39393b; 
border-width: 0px; 
border-style: solid; 
color: #C0C0C0; 
font-family: Verdana, Arial, Helvetica, sans-serif; 
background-color: #444440; 
text-align: center; 
background-image: url(images/bg.png); 
background-repeat: repeat-x; 
} 

我如何可以添加拉伸裏面這個CSS?

+0

您可以使用背景尺寸:蓋;在你的身體上設置整個元素的bg.png。 – berentrom 2014-10-28 14:34:06

回答

0

,這可能是你在找什麼

body { 
    background: url('images/bg.png') no-repeat center center fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
    margin: 0; 
} 
+0

請注意,'background-size'屬性與IE9 +兼容,但對於IE8,Mozilla Doc聲明「可以使用非標準-ms-filter函數模擬其某些功能」,請參閱https:// developer。 mozilla.org/en-US/docs/Web/CSS/background-size – 2014-10-28 14:37:01