溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

CSS3中漸變的實現(xiàn)方法

發(fā)布時間:2021-08-07 20:45:41 來源:億速云 閱讀:151 作者:chen 欄目:web開發(fā)

本篇內(nèi)容主要講解“CSS3中漸變的實現(xiàn)方法”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“CSS3中漸變的實現(xiàn)方法”吧!

1、線性漸變

語法:background: linear-gradient(direction, color-stop1, color-stop2, ...);說明:direction:默認(rèn)為to bottom,即從上向下的漸變;
stop:顏色的分布位置,默認(rèn)均勻分布,例如有3個顏色,各個顏色的stop均為33.33%。

示例1:to left、top right、to bottom、to top

div { background:linear-gradient(to left, red , blue) } 
div { background:linear-gradient(to right, red , blue) }
div { background:linear-gradient(to bottom, red , blue) } /* 瀏覽器默認(rèn)值 */ 
div { background:linear-gradient(to top, red , blue) }
分別產(chǎn)生“從右到左”、“從左到右”、“從上到下”、“從下到上”的“紅色–綠色”漸變 
CSS3中漸變的實現(xiàn)方法

示例2:to right bottom、to right top、to left bottom、to left top

div { background: linear-gradient(to right bottom, red , blue); }
div { background: linear-gradient(to right top, red , blue); }
div { background: linear-gradient(to left bottom, red , blue); } 
div { background: linear-gradient(to left top, red , blue); }

分別產(chǎn)生到“右下角”、“右上角”、“左下角”、“左上角”的漸變 
CSS3中漸變的實現(xiàn)方法

示例3:使用角度漸變

div { background: linear-gradient(10deg, red, blue) } 
CSS3中漸變的實現(xiàn)方法

2、徑向漸變

徑向漸變不同于線性漸變,線性漸變是從“一個方向”向“另一個方向”的顏色漸變,而徑向漸變是從“一個點”向四周的顏色漸變

語法:background: radial-gradient(center, shape, size, start-color, ..., last-color);說明:center:漸變起點的位置,可以為百分比,默認(rèn)是圖形的正中心。
shape:漸變的形狀,ellipse表示橢圓形,circle表示圓形。默認(rèn)為ellipse,如果元素形狀為正方形的元素,則ellipse和circle顯示一樣。
size:漸變的大小,即漸變到哪里停止,它有四個值。 closest-side:最近邊;
farthest-side:最遠(yuǎn)邊; closest-corner:最近角; farthest-corner:最遠(yuǎn)角

示例1:多顏色點均勻分布

div { background: radial-gradient(red, green, blue); } 
以中心(50% 50%)為起點,到最遠(yuǎn)角(farthest-corner),從red到green、blue的均勻漸變 

CSS3中漸變的實現(xiàn)方法

EG:div { background: -webkit-radial-gradient(50% 50%, farthest-corner, red, green, blue); } 或 div { background: -webkit-radial-gradient(center, farthest-corner, red, green, blue); }

示例2:多顏色節(jié)點不均勻分布

div { background: radial-gradient(red 5%, green 15%, blue 60%); } 
CSS3中漸變的實現(xiàn)方法

示例3:設(shè)置漸變形狀

div { background: radial-gradient(circle, red, yellow, green); } 
div { background: radial-gradient(ellipse, red, yellow, green); } 
CSS3中漸變的實現(xiàn)方法

circle:漸變?yōu)樽畲蟮膱A形; ellipse:根據(jù)元素形狀漸變,元素為正方形是顯示效果與circle無異。

示例4:不同尺寸的漸變

size指定了漸變的大小,即漸變到哪里停止,它有四個值。
closest-side:最近邊; farthest-side:最遠(yuǎn)邊; closest-corner:最近角; farthest-corner:最遠(yuǎn)角

div { background: radial-gradient(60% 40%, closest-side, blue, green, yellow, black); } 
div { background: radial-gradient(60% 40%, farthest-side, blue, green, yellow, black); }
div { background: radial-gradient(60% 40%, closest-corner, blue, green, yellow, black); }
div { background: radial-gradient(60% 40%, farthest-corner, blue, green, yellow, black); }
CSS3中漸變的實現(xiàn)方法

3、重復(fù)漸變

(1)重復(fù)性線性漸變

div { background: repeating-linear-gradient(red, yellow 10%, green 20%); }
說明:10%的位置為yellow,20%的位置為green,然后按照這20%向下重復(fù) 
CSS3中漸變的實現(xiàn)方法

(2)重復(fù)性徑向漸變

div { background: repeating-radial-gradient(red, yellow 10%, green 20%); } 
CSS3中漸變的實現(xiàn)方法

到此,相信大家對“CSS3中漸變的實現(xiàn)方法”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI