Home>Article>Web Front-end> How to set gradient in css

How to set gradient in css

青灯夜游
青灯夜游 Original
2021-04-20 17:52:52 10366browse

Method: 1. Use linear-gradient() to implement linear gradient, the syntax is "linear-gradient (angle, starting and ending color list)"; 2. Use radial-gradient() to implement radial gradient, the syntax is "radial -gradient (size position, starting and ending colors)".

How to set gradient in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

linear-gradient() function--linear gradient

linear-gradient() function is used to create an "image" of a linear gradient .

To create a linear gradient, you need to specify two colors. You can also achieve gradient effects in different directions (specified as an angle). If the direction is not specified, the gradient will default from top to bottom.

Syntax:

linear-gradient(direction, color-stop1, color-stop2, ...);

Parameters:

Value Description
direction Specify the direction (or angle) of the gradient using an angle value.
color-stop1, color-stop2,... is used to specify the starting and ending colors of the gradient.

Code example (consider browser compatibility):

    线性渐变  
基本线性渐变--自上而下
基本线性渐变--45度角

Rendering:

How to set gradient in css

radial-gradient() function--radial gradient

radial-gradient() function is created with radial gradient" image".

The radial gradient is defined by the center point. Example:

How to set gradient in css

To create a radial gradient you must set two stop colors.

css Radial color gradients (Radial Gradients) are different from linear gradients (linear gradients). It does not gradient along one direction, but takes a point as the center and radiates gradients around 360 degrees.

Syntax:

radial-gradient(shape size at position, start-color, ..., last-color);

Parameter value:

Value Description
shape Determine the type of circle:
  • ellipse (default): Specifies the radial gradient of the ellipse.
  • circle: Specify the radial gradient of the circle
size Define the size of the gradient, possible values:
  • farthest-corner (default): specifies the radius length of the radial gradient from the center of the circle to the corner farthest from the center
  • closest-side: specifies the radius length of the radial gradient from the center of the circle to the corner farthest from the center The side closest to the center of the circle
  • closest-corner: Specifies the radius length of the radial gradient from the center of the circle to the corner closest to the center of the circle
  • farthest-side: Specifies the radius length of the radial gradient from the center of the circle To the edge farthest from the center of the circle
position defines the position of the gradient. Possible values:
  • center(default): Set the middle ordinate value of the center of the radial gradient circle.
  • top: Set the top to the ordinate value of the center of the radial gradient circle.
  • bottom: Set the bottom to the ordinate value of the center of the radial gradient circle.
start-color, ..., last-color is used to specify the starting and ending colors of the gradient.

Example:

     

径向渐变 - 形状

椭圆形 Ellipse(默认):

圆形 Circle:

注意: Internet Explorer 9 及之前的版本不支持渐变。

Rendering:

How to set gradient in css

    径向渐变  
径向渐变
径向渐变

How to set gradient in css

(Learning video sharing:css video tutorial)

The above is the detailed content of How to set gradient in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn