2017-10-07 225 views
-2

我希望我的背景圖像具有從左(粉紅色)到右(藍色)而不是從上到下的線性漸變顏色。我怎樣才能做到這一點?背景圖像上的線性漸變

代碼:

body{ 
    background-image:linear-gradient(rgba(198, 115, 115, 0.5),rgba(47, 52, 172, 0.5)),url(people.jpg); 
    background-repeat: no-repeat; 
    background-size: cover; 
    height:100vh; 
} 
+0

使用最新的和常規梯度語法:'背景圖像:線性梯度(向右,RGBA(198,115,115 ,0.5),rgba(47,52,172,0.5)),url(people.jpg); ' –

+0

@ G-Cyr不要在評論中回答問題:「回答問題或爲現有答案提供備用解決方案;相反,發佈實際答案(或編輯以擴展現有答案);」 https://stackoverflow.com/help/privileges/comment – Jesus

+0

@RyanEarnshaw當它看起來像一個錯字或者只是拼寫錯誤的語法時,如果這真的值得真正的答案,它永遠不會是顯而易見的。不可能在大多數時間評估OP的知識或疲倦...... :) –

回答

0

下面是簡單的例子,隨便問,如果有什麼不太明白:

html, body { 
 
    width: 100%; 
 
    height: 100%; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
.bg-img { 
 
    width: 100%; 
 
    height: 100%; 
 
    background: url("http://unsplash.it/1200x800") center center no-repeat; 
 
    background-size: cover; 
 
} 
 
.bg-img:before { 
 
    content: ''; 
 
    position: absolute; 
 
    top: 0; 
 
    right: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    background-image: linear-gradient(to bottom right, #002f4b, #dc4225); 
 
    opacity: .8; 
 
}
<div class="bg-img"></div>

0

您需要在添加to right您梯度線

就像這樣:

body{ 
 
    background-image:linear-gradient(to right, rgba(198, 115, 115, 0.5),rgba(47, 52, 172, 0.5)),url(people.jpg); 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    height:100vh; 
 
}

您可以瞭解從本評論here

0

演示:看https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient

official on w3c

線性漸變信達x是:

<linear-gradient> = linear-gradient(
[ [ <angle> | to <side-or-corner> ] ,]? 
<color-stop>[, <color-stop>]+ 
) 

<side-or-corner> = [left | right] || [top | bottom]

的第一個參數的函數指定漸變線,這使梯度的方向,並且確定顏色擋塊如何定位。它可能被省略;如果是這樣,它默認爲'到底部'。

body{ 
 
    background-image:linear-gradient(to right,rgba(198, 115, 115, 0.5),rgba(47, 52, 172, 0.5)),url(http://lorempixel.com/600/400/people); 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    height:100vh; 
 
}

0

body{ 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 
    height:100vh; 
 
    background-image: linear-gradient(to bottom, rgba(198, 115, 115, 0.5) ,rgba(47, 52, 172, 0.5) 100%),url(https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png); 
 

 
}