2014-10-28 76 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