2015-03-03 51 views
0

這是我的CSS ...如何使用css爲body標籤設置背景圖片?

body{  
    background: url(<?php echo base_url()."images/1.jpg";?>) no-repeat center 
    center fixed; 
    background-size: cover; 
    -moz-background-size: cover; 

    -webkit-background-size: cover; 

    -o-background-size: cover; 
    height: 100%; 

    position:absolute; 
    width:100%; 
} 

我想設置圖像作爲背景完全適合屏幕尺寸。現在圖像顯示爲完整背景,但圖像的某些較低部分未顯示。 那麼解決方案是什麼?

+2

組後臺尺寸:100%100%,而不是蓋 – jbutler483 2015-03-03 10:18:34

+1

請張貼此評論爲answer..It工作.. – 2015-03-03 10:21:36

回答

3

您可以將background-size設置爲100% 100%來代替「拉伸」圖像。

注意。 canIuse指出前綴不需要用於背景大小的屬性。

body { 
 
    background: url(http://placekitten.com/g/300/300) no-repeat center center fixed; 
 
    background-size: 100% 100%; 
 
    height: 100%; 
 
    position: absolute; 
 
    width: 100%; 
 
}

+0

您好,它不工作鉻,只適用於Firefox的工作 – 2015-03-03 11:46:43

+0

@KedarB:哪個版本的Chrome? (我是最新的,它很好?) – jbutler483 2015-03-03 11:47:38

+0

42.0.2311.11 dev -m(64位),它說它是最新的 – 2015-03-03 11:50:09