2015-06-22 67 views
1

我想将背景图像设置为我的html页面。如何将背景图像设置为全屏

所以我有这样的代码:

body{ 
    background: url("background_image.jpg") no-repeat scroll center center/100% auto; 
} 

这是我的HTML页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
    <link type="text/css" rel="stylesheet" href="css/style.css" /> 
</head> 
<body> 



</body> 
</html> 
与此代码

因此,背景图像没有填满屏幕。

我想显示在全宽度和高度的图像

+0

请多关照你的语言。这很难理解。我试图为你解决它,请检查我是否正确解释你的问题。 – Dakkaron

+0

这就是你想要的吗? https://jsfiddle.net/r3g3ucem/ –

+0

是的,是这样的。对不起,我的英语 – bircastri

回答

4

尝试使用这个CSS代码:

body{ 
    background: url(backgroud-image.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
} 

html{ 
     background: url(backgroud-image.jpg) no-repeat center center fixed; 
     -webkit-background-size: cover; 
     -moz-background-size: cover; 
     -o-background-size: cover; 
     background-size: cover; 
    } 
+0

该代码,在Mozilla Firefox中工作,但如果我尝试打开我的html页面,请在Goole Chrome,我无法看到所有图像 – bircastri

+0

好吧,尝试改变身体在CSS代码中的HTML –

0

试试这个CSS:

body{ 
    background: url("background_image.jpg") no-repeat scroll center top/cover auto; 
} 

希望有所帮助!

+0

不适用您的代码 – bircastri

+0

对不起,我的坏! –