2017-05-03 89 views
0

我在我的網站上工作,我已經添加了一些圖像,現在我想設置一個背景,主要,其他人將會覆蓋它,這可能嗎?CSS:如何設置適合屏幕的背景圖片?

輸入background-image:url("myphoto.jpg")不適用於我。有任何想法嗎?謝謝!

+1

您可以發佈您的代碼? – Nimish

+1

你能爲我們提供一些代碼嗎? – Gabbax0r

+2

[在後臺拉伸和縮放CSS圖像 - 僅限CSS]可能的副本(http://stackoverflow.com/questions/1150163/stretch-and-scale-a-css-image-in-the-background-與-css-only) –

回答

0
body { 
     background: url("myphoto.jpg") no-repeat center center fixed; 
     -webkit-background-size: cover; 
     -moz-background-size: cover; 
     -o-background-size: cover; 
     background-size: cover; 
    } 
+1

我不工作,圖片無法加載。 :/ – Luigi

+0

@Luigi,圖片url必須是相對於CSS文件的。例如,如果您的CSS文件位於相對於html文件的子文件夾中,則可能需要將路徑更改爲如下所示:url(「../ myphoto.jpg」) – adibble

1

將背景課程授予您想要應用背景圖像的潛水。並給CSS按如下: 這是你如何能做到:

<div class="background"></div> 

and style css would be: 

.background{ 
background: url("myphoto.jpg") no-repeat center center; 
background-repeat: no-repeat; 
background-size: 100% 100%; 
} 
0

@Hiren是正確的,但你需要「找到」所需的圖像,FX。如果我們說,我有我的WWW文件夾至極是我的主文件夾,我有一個index.html,並呼籲IMG的子文件夾,裏邊有我有myphoto.jpg

則應設置爲網址如下: url("img/myphoto.jpg")

body { 
 
     background: url("https://www.qdtricks.net/wp-content/uploads/2016/05/hd-road-wallpaper.jpg") no-repeat center center fixed; 
 
     -webkit-background-size: cover; 
 
     -moz-background-size: cover; 
 
     -o-background-size: cover; 
 
     background-size: cover; 
 
    }