在html中,可以使用radial-gradient函數(shù)設(shè)置徑向漸變,只需要在元素background屬性里加入“background:radial-gradient(起始位置, 形狀,大小, 顏色,顏色,顏色)”即可。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
徑向漸變:從一個(gè)點(diǎn)到四周的顏色的過渡變化。
徑向漸變?nèi)鐖D所示:
語法:(必須加瀏覽器前綴)
background: radial-gradient(center, shape, size, start-color, ..., last-color);
center:漸變起點(diǎn)的位置,可以為百分比,默認(rèn)是圖形的正中心。
shape:漸變的形狀,ellipse表示橢圓形,circle表示圓形。默認(rèn)為ellipse,如果元素形狀為正方形的元素,則ellipse和circle顯示一樣。
size:關(guān)于徑向漸變的大?。?/p>
closest-side 最近邊
farthest-side 最遠(yuǎn)邊
closest-corner 最近角
farthest-corner 最遠(yuǎn)角
實(shí)現(xiàn)代碼如下:
p{ width:500px; height:300px; margin:40px auto; background:-webkit-radial-gradient(center,closest-corner,red,yellow,green); }
擴(kuò)展資料:
線性漸變:從一個(gè)方向到另一個(gè)方向到另一個(gè)方向的顏色的變化
標(biāo)準(zhǔn)模式的語法(不添加瀏覽器前綴):
background:linear-gradient(direction,color-stop1,color-stop2)
說明:direction默認(rèn)值是to bottom,即從上往下
stop:顏色的分布位置,默認(rèn)均勻分布(平均分布)
兼容模式的語法(添加瀏覽器前綴):
background:-webkit-linear-gradient(direction,color-stop1,color-stop2)
說明:direction值不能加to,該值表示顏色從該方向開始漸變,與上面相反
stop:顏色的分布位置,默認(rèn)均勻分布(平均分布)
漸變方向:前面實(shí)現(xiàn)了上下或左右漸變,接下來介紹對(duì)角線型漸變
1、to left to right to top(上下或左右漸變)
2、to left top to right bottom(對(duì)角線漸變)
3、漸變線角度的變化
例如:標(biāo)準(zhǔn)模式 : 40deg 40度
兼容模式 : 90 – 40deg
線性漸變:顏色的分布(顏色區(qū)域大小):
linear-gradient(方向, 顏色1 20%,顏色2 30%,顏色3 )
到20%這個(gè)位置仍然是顏色1 出了20% 開始向顏色2漸變
代碼如下所示:
div{ width:500px; height:300px; margin:100px auto; background-image: -webkit-linear-gradient(left, red, yellow); }
推薦學(xué)習(xí):html視頻教程