自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

CSS漸變屬性的特效,你學會了嗎?

開發(fā) 前端
Background-image和Border-image屬性都可以用漸變作為圖片內(nèi)容。 下面,我們就分別來看看這幾個屬性的效果。

頁面中如果有兩種或多種指定顏色之間的平滑過渡的漸變效果,會使得我們的視覺效果瞬間提升幾個檔次,在CSS3中有提供的多個漸變方式屬性就能讓我們輕松實現(xiàn)這樣的漸變效果。

目前CSS漸變屬性有六個,分別為:linear-gradient(線性漸變),repeating-linear-gradient(重復線性漸變),radial-gradient(徑向漸變),repeating-radial-gradient(重復徑向漸變),conic-gradient(錐形漸變),repeating-conic-gradient(重復錐形漸變); CSS漸變屬性作用是從一種顏色平滑漸變到另一種顏色的圖像,那么background-imageborder-image屬性都可以用漸變作為圖片內(nèi)容。 下面,我們就分別來看看這幾個屬性的效果

linear-gradient和repeating-linear-gradient

線性漸變以直線的方式,可向左、向右、向上、向下、對角方向延伸,使用頻率很高。要創(chuàng)建線性漸變,需要指定兩種及以上的顏值和方向,如果未指定方向,默認為上到下漸變。
使用語法:

background-image: linear-gradient(direction, ColorStop1, ColorStop2, ...,ColorStopN);
  1. direction的取值有: to right(向右)、to bottom(向下)、to bottom right(向右下角)、180deg(向下)
  2. ColorStop為指定漸變顏色和漸變位置,顏色代碼可以是十六進制顏色代碼,RGB顏色代碼。位置可以是百分比也可以是像素
 <div class="bg">
</div>

.bg{
width: 200px;
height: 200px;
background-image: linear-gradient( rgb(123, 255, 0),rgb(119, 0, 255));
}

默認從上到下。

.bg{
width: 200px;
height: 200px;
background-image: linear-gradient(to bottom right, rgb(123, 255, 0),rgb(119, 0, 255));
}

指定方向從左上角到右下角。

.bg{
width: 200px;
height: 200px;
background-image: linear-gradient(to bottom right, rgb(123, 255, 0),rgb(119, 0, 255),rgb(255, 0, 43));
}

指定方向從左上角到右下角,設(shè)置多種漸變顏色。

.bg{
width: 200px;
height: 200px;
background-image: linear-gradient(to bottom right, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43));
}


指定方向從左上角到右下角,設(shè)置多種漸變顏色及顏色作用位置。

repeating-linear-gradient用得可能比較少,它是基于linear-gradient進行重復平鋪操作。

.bg{
width: 200px;
height: 200px;
background-image: repeating-linear-gradient(to bottom, rgb(123, 255, 0) 0 ,rgb(251, 255, 0)10%,rgb(255, 0, 43)15%);
}

前面都是漸變背景,我們再來看看漸變邊框是什么效果。

.bg{
width: 200px;
height: 200px;
border-width:10px;
border-style:solid;
border-image:linear-gradient(to bottom right, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10;
}

radial-gradient

徑向漸變以由中心點由或者橢圓向外擴散,使用語法。

background-image: radial-gradient(shape size at position, ColorStop, ..., ColorStopN);
  1. shape 圓類型,就兩種:ellipse(橢圓)和circle (圓),默認ellipse
  2. size 漸變大小,分別有farthest-corner(從圓心到圓最遠的角為半徑),farthest-side(從圓心到圓最遠的邊為半徑),closest-corner(從圓心到圓最近的角為半徑),closest-side(從圓心到圓最近的邊為半徑),Size,默認是farthest-corner,
  3. position 位置:left,right,top,bottom,center或者數(shù)值比分比,默認是center
  4. ColorStop,漸變顏色和漸變位置radial-gradient的用法和linear-gradient的用法相似
.bg{
width: 200px;
height: 200px;
background-image: radial-gradient( rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43));
}

.bg{
width: 200px;
height: 200px;
border-width:10px;
border-style:solid;
border-image:radial-gradient(rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10;
}

conic-gradient

一般情況下,用conic-gradient的場景比較少,但我們也可以基本了解一下。其基本語法:

background-image: conic-gradient(from angle at position,ColorStop, ...,ColorStopN);
  1. from angle 起點角度,默認0deg
  2. position 位置:left,right,top,bottom,center或者數(shù)值比分比,默認是center
  3. ColorStop,漸變顏色和漸變位置
.bg{
width: 200px;
height: 200px;
background-image: conic-gradient( rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43));
}

.bg{
width: 200px;
height: 200px;
background-image: conic-gradient(from 90deg at left, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43));
}

.bg{
width: 200px;
height: 200px;
border-width:10px;
border-style:solid;
border-image:conic-gradient(from 90deg at left, rgb(123, 255, 0) 0,rgb(251, 255, 0) 15%,rgb(119, 0, 255) 35% 80%,rgb(255, 0, 43)) 1 10;
}

責任編輯:姜華 來源: 今日頭條
相關(guān)推薦

2022-10-27 09:13:58

CSSGradient

2022-07-08 09:27:48

CSSIFC模型

2022-05-06 09:00:56

CSS元素Flex

2022-10-09 09:30:33

CSS瀏覽器十六進制

2023-11-08 10:12:40

架構(gòu)函數(shù)元素

2024-07-31 08:26:47

2024-01-16 08:22:42

Gradient線性梯度

2023-08-22 10:25:19

CSS動畫網(wǎng)頁

2024-05-30 09:43:00

2022-04-01 09:02:19

CSS選擇器HTML

2024-02-02 11:03:11

React數(shù)據(jù)Ref

2024-01-02 12:05:26

Java并發(fā)編程

2023-08-01 12:51:18

WebGPT機器學習模型

2024-02-04 00:00:00

Effect數(shù)據(jù)組件

2023-07-26 13:11:21

ChatGPT平臺工具

2024-01-19 08:25:38

死鎖Java通信

2023-01-10 08:43:15

定義DDD架構(gòu)

2022-12-06 08:37:43

2024-05-29 07:47:30

SpringJava@Resource

2022-06-16 07:50:35

數(shù)據(jù)結(jié)構(gòu)鏈表
點贊
收藏

51CTO技術(shù)棧公眾號