CSS3 radial gradient (radial-gradient)
The previous article introduced CSS3 linear gradient (linear-gradient). This article will introduce radial-gradient (radial gradient) and repeated gradient (linear repetition and radial repetition ). In the past, gradient effects were made into images like shadows and rounded corners. Currently, CSS 3 can be directly written for implementation.
CSS3 radial gradient and linear gradient are very similar. Let's first look at its syntax:
. Code
- -Moz-radial-gradient ([ |,]? [ | ,]? , [, ] *);
- -Webkit-radial-gradient ([ |,]? [ | ,]? , [, ] *);
Apart from the starting position, direction, and color that you have seen in a linear gradient, the radial gradient allows you to specify the shape (circular or elliptical) and size (closest end, closest angle, the far-end, farthest-angle, including or covering (closest-side, closest-corner, farthest-side, farthest-corner, contain or cover )). Color stops: Like linear gradient, you should define the starting and ending colors of the gradient along the gradient line. In order to better understand its specific usage, we will mainly compare the specific usage of CSS3 radial gradient through different examples. We will share a best UI front-end framework!
Example 1:
. Code
- Background:-moz-radial-gradient (# ace, # f96, # 1E90FF );
- Background:-webkit-radial-gradient (# ace, # f96, # 1E90FF );
Effect:
Example 2:
. Code
- Background:-moz-radial-gradient (# ace 5%, # f96 25%, # 1E90FF 50% );
- Background:-webkit-radial-gradient (# ace 5%, # f96 25%, # 1E90FF 50% );
The effect is as follows:
From the code in the above two examples, we found that they wanted the same starting and ending colors, but in example 2, we located some data. Why is this big difference? In fact, although the radial gradient has the same starting and ending colors, but when no position is set, the default color is the even interval, which is the same as the linear gradient above, however, when the gradient position is set, the gradient will be taken according to the gradient position. This is the difference between the sample and the example: although the circle has the same starting and ending colors, however, in Example 1, a gradient with a uniform color interval is selected by default, while in example 2, each color has a specific position. Share the best UI front-end framework!
Example 3:
. Code
- Background:-moz-radial-gradient (bottom left, circle, # ace, # f96, # 1E90FF );
- Background:-webkit-radial-gradient (bottom left, circle, # ace, # f96, # 1E90FF );
The effect is as follows:
Example 4:
. Code
- Background:-moz-radial-gradient (bottom left, ellipse, # ace, # f96, # 1E90FF );
- Background:-webkit-radial-gradient (bottom left, ellipse, # ace, # f96, # 1E90FF );
The effect is as follows:
In Example 3 and example 4, we can see from the effect that the shape is different. In the example, the three-way circle and the four-way elliptical shape are also known as their differences in shape. However, when we return to the code of the two examples, it is clear that in the example 3, the shape is set to circle, and in the example 4, ellipse, in other words, in the radial gradient, we can set its shape.
Example 5:
. Code
- Background:-moz-radial-gradient (ellipse closest-side, # ace, # f96 10%, # 1E90FF 50%, # f96 );
- Background:-webkit-radial-gradient (ellipse closest-side, # ace, # f96 10%, # 1E90FF 50%, # f96 );
The effect is as follows:
Example 6:
. Code
- Background:-moz-radial-gradient (ellipse farthest-corner, # ace, # f96 10%, # 1E90FF 50%, # f96 );
- Background:-webkit-radial-gradient (ellipse farthest-corner, # ace, # f96 10%, # 1E90FF 50%, # f96 );
The effect is as follows:
From the code in Example 5 and Example 6, we can clearly understand that in Example 5, we applied closest-side and farthest-corner in Example 6. In this way, we can also set the Size for the radial gradient: different options of size (closest-side, closest-corner, farthest-side, farthest-corner, contain or cover) points to the point used to define the circle or elliptical size. For example, the near-side of an elliptic V. S. has different sizes. Example 5 is the distance from the starting point (center) to the near edge, and Example 6 is the distance from the starting point to the far angle. Share the best UI front-end framework!
Example 7:
. Code
- Background:-moz-radial-gradient (circle closest-side, # ace, # f96 10%, # 1E90FF 50%, # f96 );
- Background:-webkit-radial-gradient (circle closest-side, # ace, # f96 10%, # 1E90FF 50%, # f96 );
The effect is as follows:
Example 8:
The effect is as follows:
Example 7 and Example 8 demonstrate the circle's near edge VS far edge. The gradient size of the circle in Example 7 is determined by the distance from the start point (center) to the near edge, the circle in Example 8 is determined by the distance from the starting point to the far edge.
Example 9:
. Code
- Background:-moz-radial-gradient (# ace, # f96, # 1E90FF );
- Background:-webkit-radial-gradient (# ace, # f96, # 1E90FF );
The effect is as follows:
Example 10:
. Code
- Background:-moz-radial-gradient (contain, # ace, # f96, # 1E90FF );
- Background:-webkit-radial-gradient (contain, # ace, # f96, # 1E90FF );
The effect is as follows:
Example 9 and Example 10 demonstrate circle inclusion. Here you can see the default circle of Example 9, which is the same gradient version but contains the circle of Example 10. Share the best UI front-end framework!
Finally, let's take a look at two instances: Application Center positioning and full sized, as shown below:
. Code
- /* Firefox 3.6 + */
- Background:-moz-radial-gradient (circle, # ace, # f96 );
- /* Safari 4-5, Chrome 1-9 */
- /* Can't specify a percentage size? Laaaaaame .*/
- Background:-webkit-gradient (radial, center, 0, center, 460, from (# ace), to (# f96 ));
- /* Safari 5.1 +, Chrome 10 + */
- Background:-webkit-radial-gradient (circle, # ace, # f96 );
The effect is as follows:
The following example applies Positioned and Sized. See the code and results:
. Code
- /* Firefox 3.6 + */
- /*-Moz-radial-gradient ([|,]? [|,]? , [,] *) */
- Background:-moz-radial-gradient (80% 20%, closest-corner, # ace, # f96 );
- /* Safari 4-5, Chrome 1-9 */
- Background:-webkit-gradient (radial, 80% 20%, 0, 80% 40%, 100, from (# ace), to (# f96 ));
- /* Safari 5.1 +, Chrome 10 + */
- Background:-webkit-radial-gradient (80% 20%, closest-corner, # ace, # f96 );
The effect is as follows:
We have finished introducing the two gradient methods of CSS3. Let's take a look at CSS3.Repeating Gradient).
If you want to repeat a gradient, you can use-moz-repeating-linear-gradient (repeating linear gradient) and-moz-repeating-radial-gradient (repeating radial gradient ). In the following example, each instance specifies two start and end colors and repeats infinitely. Share the best UI front-end framework!
. Code
- Background:-moz-repeating-radial-gradient (# ace, # ace 5px, # f96 5px, # f96 10px );
- Background:-webkit-repeating-radial-gradient (# ace, # ace 5px, # f96 5px, # f96 10px );
- Background:-moz-repeating-linear-gradient (top left-45deg, # ace, # ace 5px, # f96 5px, # f96 10px );
- Background:-webkit-repeating-linear-gradient (top left-45deg, # ace, # ace 5px, # f96 5px, # f96 10px );
Effect:
There is something about CSS3 gradient. After reading it, you will surely think about it. What aspects does it mainly use? This is much more. The simplest thing is to create a background. We can also use it to make some beautiful buttons and use it to make patterns, here I will list several sample codes for creating patterns:
HTML code:
. Code
-
CSS code:
. Code
- Ul {
- Overflow: hidden;
- Margin-top: 20px;
- }
- Li {
- Width: 150px;
- Height: 80px;
- Margin-bottom: 10px;
- Float: left;
- Margin-right: 5px;
- Background: # ace;
- /* Controls the size */
- -Webkit-background-size: 20px 20px;
- -Moz-background-size: 20px 20px;
- Background-size: 20px 20px;
- }
-
- Li. gradient1 {
- Background-image:-webkit-gradient (
- Linear,
- 0 100%, 100% 0,
- Color-stop (. 25, rgba (255,255,255,. 2 )),
- Color-stop (. 25, transparent ),
- Color-stop (. 5, transparent ),
- Color-stop (. 5, rgba (255,255,255,. 2 )),
- Color-stop (. 75, rgba (255,255,255,. 2 )),
- Color-stop (. 75, transparent ),
- To (transparent)
- );
- Background-image:-moz-linear-gradient (
- 45deg,
- Rgba (255,255,255,. 2) 25%,
- Transparent 25%,
- Transparent 50%,
- Rgba (255,255,255,. 2) 50%,
- Rgba (255,255,255,. 2) 75%,
- Transparent 75%,
- Transparent
- );
- Background-image:-o-linear-gradient (
- 45deg,
- Rgba (255,255,255,. 2) 25%,
- Transparent 25%,
- Transparent 50%,
- Rgba (255,255,255,. 2) 50%,
- Rgba (255,255,255,. 2) 75%,
- Transparent 75%,
- Transparent
- );
- Background-image: linear-gradient (
- 45deg,
- Rgba (255,255,255,. 2) 25%,
- Transparent 25%,
- Transparent 50%,
- Gba (255,255,255,. 2) 50%,
- Rgba (255,255,255,. 2) 75%,
- Transparent 75%,
- Transparent
- );
- }
-
- Li. gradient2 {
- Background-image:-webkit-gradient (linear, 0 0,100% 100%,
- Color-stop (. 25, rgba (255,255,255,. 2), color-stop (. 25, transparent ),
- Color-stop (. 5, transparent), color-stop (. 5, rgba (255,255,255,. 2 )),
- Color-stop (. 75, rgba (255,255,255,. 2), color-stop (. 75, transparent ),
- To (transparent ));
- Background-image:-moz-linear-gradient (-45deg, rgba (255,255,255,. 2) 25%, transparent 25%,
- Transparent 50%, rgba (255,255,255,. 2) 50%, rgba (255,255,255,. 2) 75%,
- Transparent 75%, transparent );
- Background-image:-o-linear-gradient (-45deg, rgba (255,255,255,. 2) 25%, transparent 25%,
- Transparent 50%, rgba (255,255,255,. 2) 50%, rgba (255,255,255,. 2) 75%,
- Transparent 75%, transparent );
- Background-image: linear-gradient (-45deg, rgba (255,255,255,. 2) 25%, transparent 25%,
- Transparent 50%, rgba (255,255,255,. 2) 50%, rgba (255,255,255,. 2) 75%,
- Transparent 75%, transparent );
- }
-
- Li. gradient3 {
- Background-image:-webkit-gradient (linear, 0 0, 0 100%, color-stop (. 5, rgba (255,255,255 ,. 2), color-stop (. 5, transparent), to (transparent ));
- Background-image:-moz-linear-gradient (rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- Background-image:-o-linear-gradient (rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- Background-image: linear-gradient (rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- }
-
- Li. gradient4 {
- Background-image:-webkit-gradient (linear, 0 0,100% 0, color-stop (. 5, rgba (255,255,255 ,. 2), color-stop (. 5, transparent), to (transparent ));
- Background-image:-moz-linear-gradient (0deg, rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- Background-image:-o-linear-gradient (0deg, rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- Background-image: linear-gradient (0deg, rgba (255,255,255,. 2) 50%, transparent 50%, transparent );
- }
-
- Li. gradient5 {
- Background-image:-webkit-gradient (linear, 0 0,100% 100%, color-stop (. 25, #555), color-stop (. 25, transparent), to (transparent )),
- -Webkit-gradient (linear, 0 100%, 100% 0, color-stop (. 25, #555), color-stop (. 25, transparent), to (transparent )),
- -Webkit-gradient (linear, 0 0,100% 100%, color-stop (. 75, transparent), color-stop (. 75, #555 )),
- -Webkit-gradient (linear, 0 100%, 100% 0, color-stop (. 75, transparent), color-stop (. 75, #555 ));
- Background-image:-moz-linear-gradient (45deg, #555 25%, transparent 25%, transparent ),
- -Moz-linear-gradient (-45deg, #555 25%, transparent 25%, transparent ),
- -Moz-linear-gradient (45deg, transparent 75%, #555 75% ),
- -Moz-linear-gradient (-45deg, transparent 75%, #555 75% );
- Background-image:-o-linear-gradient (45deg, #555 25%, transparent 25%, transparent ),
- -O-linear-gradient (-45deg, #555 25%, transparent 25%, transparent ),
- -O-linear-gradient (45deg, transparent 75%, #555 75% ),
- -O-linear-gradient (-45deg, transparent 75%, #555 75% );
- Background-image: linear-gradient (45deg, #555 25%, transparent 25%, transparent ),
- Linear-gradient (-45deg, #555 25%, transparent 25%, transparent ),
- Linear-gradient (45deg, transparent 75%, #555 75% ),
- Linear-gradient (-45deg, transparent 75%, #555 75% );
- }
-
- Li. gradient6 {
- Background-image:-webkit-gradient (linear, 0 0, 0 100%, color-stop (. 5, transparent), color-stop (. 5. rgba (200, 0, 0 ,. 5), to (rgba (200, 0, 0 ,. 5 ))),
- -Webkit-gradient (linear, 0 0,100% 0, color-stop (. 5, transparent), color-stop (. 5. rgba (200, 0, 0 ,. 5), to (rgba (200, 0, 0 ,. 5 )));
- Background-image:-moz-linear-gradient (transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 )),
- -Moz-linear-gradient (0deg, transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 ));
- Background-image:-o-linear-gradient (transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 )),
- -O-linear-gradient (0deg, transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 ));
- Background-image: linear-gradient (transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 )),
- Linear-gradient (0deg, transparent 50%, rgba (200, 0, 0,. 5) 50%, rgba (200, 0, 0,. 5 ));
- }
Effect: share the best UI front-end framework!
Good results, of course, interested friends can come here to learn more about different effects.