2016-08-11 38 views
1

我尝试设置背景图像body像为:如何在整页上制作背景图片?

body { 
 
     background: url("http://beerhold.it/1024/800") center bottom; 
 
     z-index: 10; 
 
     height: 100%; 
 
     background-repeat: no-repeat; 
 
     background-size: cover; 
 
}

但只有部分

回答

1

不要ü使用高度它显示的图像:100%。这个高度基于内容的高度。不是一个parrent块。

body { 
 
    background: url("http://beerhold.it/1024/800") center bottom; 
 
    z-index: 10; 
 
    min-height: 100vh; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    margin: 0; 
 
}

1

添加到您的代码

background: url("http://3ksks.com/pic.jpg"); 
 
background-size: 100% auto;

+0

的高度,它的工作就像前面的代码 – Dev

3
html { 
    height: 100%; 
} 

添加这一点。默认情况下,除非您设置HTML

+0

这是我的代码相同的HTML的高度设置为auto,这样的车身高度也不能100%。当我删除这个我的风格已经工作 – Dev

+0

它只适用于''身高':身高':100vh'而不是'height:100%'' – Lucian

1
body { 
    background: url("http://beerhold.it/1024/800") center bottom; 
    background-size: 100% 100%; 
    background-repeat: no-repeat; 
    background-size: cover; 
}