在上一篇《用HTML/CSS制作有趣的動態波浪形文本行》中給大家介紹了如何用用HTML/CSS制作動態波浪形文本行,感興趣的朋友可以去了解一下~
本文將繼續給大家介紹怎么用css實現一個帶有漸變邊框的圓。
首先我給大家簡單說一下實現思路:我將創建兩個 div,一個是類名為outer_circle
的外部 div,另一個是類名為inner_circle
的內部 div ;外部 div 包含帶有漸變顏色的大圓圈,內部 div 包含一個白色小圓圈,作為圓圈的內端,創建圓圈的邊界。
下面直接上完整代碼:
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title></title> <style> .outer_circle { position: relative; margin: 50px; width: 100px; height: 100px; border-radius: 50%; background: #ffffff; } .inner_circle { background-image: linear-gradient( to bottom, rgb(123, 93, 255) 0%, rgb(56, 225, 255) 100%); content: ''; position: absolute; top: -20px; bottom: -20px; right: -20px; left: -20px; z-index: -1; border-radius: inherit; } </style> </head> <body> <div class="outer_circle"> <div class="inner_circle"></div> </div> </body> </html>
效果如下圖所示:
在上述代碼中我們主要通過使用CSS linear-gradient()
函數繪制一個帶有漸變邊框的圓,linear-gradient()
函數的作用就是創建一個表示兩種或多種顏色線性漸變的圖片。
linear-gradient()
函數語法如:
.class_name { background-image: linear-gradient(direction, color1, color2 }
參數:
$direction:指定漸變移動的方向。
$color1:指定第一個色標。
$color2:它指定第二個色標。
其他用法表示:
/* 從上到下,藍色漸變到紅色 */ linear-gradient(blue, red); /* 漸變軸為45度,從藍色漸變到紅色 */ linear-gradient(45deg, blue, red); /* 從右下到左上、從藍色漸變到紅色 */ linear-gradient(to left top, blue, red); /* 從下到上,從藍色開始漸變、到高度40%位置是綠色漸變開始、最后以紅色結束 */ linear-gradient(0deg, blue, green 40%, red);
PHP中文網平臺有非常多的視頻教學資源,歡迎大家學習《css視頻教程》!