22nd Chapter CSS3 Gradient Effect
Learning Essentials:
1. Linear gradient
2. Radial gradient
This chapter mainly discusses the CSS3 background gradient function in HTML5, there are two main gradient modes: linear gradient and radial (radioactive) gradient.
A Linear gradient
CSS3 provides a gradient feature for the Linear-gradient property to implement the background color. In the past, this effect had to be done with pictures. First, let's take a look at its style sheet, as follows: Linear-gradient (azimuth, start color, end color)
Orientation: Optional parameter, orientation of the gradient. The values you can use are: to top, to top
Right, to-right, to bottom, to-bottom left, to
Left, to top left.
Start color: Required parameter, color value
End color: Required parameter, color value
Two Required parameters
Background-image:linear-gradient (Orange,green);
Add a position
Background-image:linear-gradient (to Top,orange,green);
Through the four groups of top, left, right and bottom, the gradient direction is sometimes relatively single, we can make
The position is set by the value of the angle unit. For example, 0 degrees (0deg) equivalent to top, the angle will be counterclockwise direction
Increase as your angle increases.
Set azimuth by angle, between 0 and 360 degrees, can be negative
Background-image:linear-gradient (45deg,orange,green);
Multi-color linear gradient
Background-image:linear-gradient ( -45deg,orange,green,blue,red);
Set multi-color linear position by percent
Background-image:linear-gradient ( -45deg, Orange 0, Green 20%, Blue 40%,
Red 100%);
By default: The percentage position of the starting color is 0%, the percentage of the end color is 100%, and the other position
Distribution by average. You can also use px pixels to set, but calculate the trouble points.
Combine backgrounds and use transparent gradients for a strong sense of layering
background-color:red;
Background-image:
RGBA (0,0,0,0));
Linear-gradient (To
Top
Right
Rgba (0,0,0,0.6),
Repeating Gradient property values
Background-image:repeating-linear-gradient (to top, orange 10px, green
30px);
Some support is mentioned here, stating that it is possible that the gradient is not yet complete, but you can use it by adding a prefix.
Specific which is not perfect, has been unable to verify, the version is too long. It is supported with a prefix and does not support a full
The format is as follows:
Plus compatible prefixes
Background-image:-webkit-linear-gradient (to top, orange, green);
Background-image:-moz-linear-gradient (to top, orange, green);
Background-image:-o-linear-gradient (to top, orange, green);
Background-image:linear-gradient (to top, orange, green);
Repeating-linear-gradient property value and Linear-gradient are basically the same, not repeat.
Two Radial gradient
CSS3 provides a radial gradient, also known as a radioactive gradient: the Radial-gradient property value. It is from a point
Extend in a way that radiates around. The property value style sheet is as follows:
Radial-gradient (azimuth, start color, end color)
Optional parameters, radial orientation. The values you can use are: pixel, percentile, fixed value, or composite use
Start color required parameter, color value
End color required parameter, color value
Two Required parameters
Background-image:radial-gradient (orange, green);
If you want to set the first optional parameter, one of the practices is set to: Cirlce (round) or ellipse (elliptical
Round). The default is ellipse.
Background-image:radial-gradient (Circle, Orange, green);
Shape description
Circle Circle
Ellipse ellipse, default value
Not only can you set the shape, you can also set the divergence direction of the shape
Background-image:radial-gradient (circle at top, orange, green);
Direction description
Top out of the roof
Left divergence
Right divergence
Bottom diverging from the bottom
Center diverging from the middle
You can also compound the direction, such as the lower right
Background-image:radial-gradient (circle at right bottom, orange,
Green);
You can set the divergence distance, which is the radius length of the circle
Background-image:radial-gradient (Circle Closest-side, Orange, green);
Radius keyword Description
closest-side Specifies the radius length of the radial gradient from the center to the nearest edge from the center point
Closest-corner Specifies the radius length of the radial gradient from the center to the nearest corner from the center point
farthest-side Specifies the radius length of the radial gradient from the center to the farthest edge from the center
Farthest-corner Specifies the radius length of the radial gradient from the center to the point farthest from the center
Farthest-corner
Keywords have a bit of a mouthful, you can use pixels to represent radii, but not percent
Background-image:radial-gradient (Circle 50px, Orange, green);
Similarly, there are repeated background patterns
Background-image:repeating-radial-gradient (Circle 50px, Orange,
Green);
Compatibility mode
Background-image:-webkit-radial-gradient (Circle, Orange, green);
Background-image:-moz-radial-gradient (Circle, Orange, green);
Background-image:-o-radial-gradient (Circle, Orange, green);
Background-image:radial-gradient (Circle, Orange, green);
Two repeating backgrounds just add the prefix to compatibility mode.
Background-image:-webkit-repeating-radial-gradient
Background-image:-moz-repeating-radial-gradient
Background-image:-o-repeating-radial-gradient
Background-image:repeating-radial-gradient
Example
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title>css Other Styles </title>
<link rel= "stylesheet" type= "Text/css" href= "Style.css" >
<body>
<div> I'm html5</div>.
</body>
@charset "Utf-8";
div {
width:200px;
height:200px;
/*background-color:green;
Color:blue;
opacity:0.5;*/
border:10px solid Green;
/*box-shadow:10px 10px 5px 2px Gray inset;*/
outline:5px double red;
Cursor:move;
}
22nd Chapter CSS Gradient effect