2016-07-06 65 views
0

我想改變我身體的顏色,我想讓它變成黑白。這是我使用的那一刻代碼:我怎樣才能讓身體的背景顏色變成黑白

font-family: Montserrat, sans-serif; 
    background-image: url("http://vlr.tynt.com/?format=txt&key=284d869ffe43382ebe88a02cabb697ab&u=http%3A%2F%2Ft.wallpaperweb.org%2Fwallpaper%2Fnature%2F1920x1080%2FPacific_Sunset_Pismo_Beach_California.jpg&subId=cyfIqK8eur4kvOacwqm_6r&txt=&loc=http%3A%2F%2Fwallpaperweb.org%2Fwallpaper%2Fnature%2Fpacific-sunset-pismo-beach-california_40871.htm&ref=https%3A%2F%2Fwww.google.al%2F&title=Nature%3A%20Pacific%20Sunset%2C%20Pismo%20Beach%2C%20California%2C%20desktop%20wallpaper%20nr.%2040871"); 
    color: white; 
    filter: grayscale(100%); 
    -webkit-filter: grayscale(90%); 

我用Google搜索了很多,但網站顯示我的圖像時,它就像身體不作爲背景圖像的隨機圖像

+1

的可能的複製[灰度背景的CSS圖像](http://stackoverflow.com/questions/16340159/greyscale-background-css-images) –

回答

0

你在body背景不能使用過濾器,但是有一個哈克的方式用做它:before僞選擇像這樣:

body { 
 
    font-family: Montserrat, sans-serif; 
 
    color: white; 
 
    margin:0; 
 
    padding:0; 
 
} 
 
    body:before { 
 
    content: ""; 
 
    background: url("http://vlr.tynt.com/?format=txt&key=284d869ffe43382ebe88a02cabb697ab&u=http%3A%2F%2Ft.wallpaperweb.org%2Fwallpaper%2Fnature%2F1920x1080%2FPacific_Sunset_Pismo_Beach_California.jpg&subId=cyfIqK8eur4kvOacwqm_6r&txt=&loc=http%3A%2F%2Fwallpaperweb.org%2Fwallpaper%2Fnature%2Fpacific-sunset-pismo-beach-california_40871.htm&ref=https%3A%2F%2Fwww.google.al%2F&title=Nature%3A%20Pacific%20Sunset%2C%20Pismo%20Beach%2C%20California%2C%20desktop%20wallpaper%20nr.%2040871"); 
 
    background-size: cover; 
 
    position: absolute; 
 
    height:100%; 
 
    width:100%; 
 
    z-index: -1; 
 
    filter: grayscale(100%); 
 
    -webkit-filter: grayscale(90%); 
 
    }

請注意,此解決方案不支持IE或Edge。

另一種解決方案是創建一個應用了過濾器的元素,並使用絕對定位將其放在內容後面。

Source
相關問題