The previous article introduced CSS3 linear gradient (linear-gradient). This article introduces radial-gradient (radial gradient) and repeating gradient (linear repeat, radial repeat). In the past, gradient effects, like shadows and rounded corner effects, were all made into pictures. Now CSS3 can be implemented directly by writing CSS code.
CSS3 radial gradients and linear gradients are very similar. Let’s first look at their syntax:
. Code
- -moz-radial-gradient([ || ,]? [ || ,]? , ]*);
- -webkit-radial-gradient([ || ,]? [ || < ;size>,]? , [, ]*);
except Instead of the starting position, direction, and color you've seen in linear gradients, radial gradients allow you to specify the shape (circle or ellipse) and size (nearest end, closest corner, farthest end, farthest corner) of the gradient. , contain or cover (closest-side, closest-corner, farthest-side, farthest-corner, contain or cover)). Color stops: Just like with a 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 mainly compare the specific usage of CSS3 radial gradient through different examples. Share a best-used 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%);
From the codes of the above two examples, we found that they start and end with the same idea, but the second example locates some data. Why is there such a big difference? In fact, although the radial gradient has the same starting and ending colors, when the position is not set, the default colors are evenly spaced. This is the same as our previous linear gradient, but if the gradient position is set, it will follow the gradient position. Gradient, this is the difference between our example one and example: although the circles have the same starting and ending colors, in example one the default color is an evenly spaced gradient, while in example two each color has a specific position. Share one of the best UI front-end frameworks!
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: -
-
We can see from the effects of Example 3 and Example 4 that their shapes are different, the example is a three-way circle and the example is a four-way elliptical shape, that is to say, they exist in shape. difference. However, when we return to the code of the two examples, it is obvious that in example three, the shape is set to circle, and in example four, 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); 🎜>
We can clearly see from the code in Example 5 and Example 6 that in Example 5 we used closest-side and in Example 6 we used farthest-corner. This way we know that in the radial gradient we can also set the size (Size) for it: the different options for size (closest-side, closest-corner, farthest-side, farthest-corner, contain or cover) point to the ones used to define A point the size of a circle or ellipse. Example: Near side vs far corner of ellipse The two ellipses below have different sizes. Example 5 is determined by the distance from the starting point (center) to the near edge, while Example 6 is determined by the distance from the starting point to the far corner. Share one of the best UI front-end frameworks!
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); >Example 8:
The effect is as follows:
- Example 7 and 8 mainly demonstrate the near side VS far side of the circle. The gradient size of the circle in Example 7 is determined by the distance from the starting point (center) to the near side, while the circle in Example 8 is determined by the distance from the starting point to the far side.
-
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 nine and ten demonstrate the containing circle. Here you can see the default circle of example nine, a gradient version of the same, but enclosed by the circle of example ten. Share one of the best UI front-end frameworks! Finally, we are looking at two examples. One is the application of 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 center, 0, center 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, Sized, please see the code and effect:
-
- .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:
At this point we have introduced the two gradient methods of CSS3. To waste a little more time, let’s take a look at the application of 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 example below, two starting and ending colors are specified for each instance and repeated infinitely. Share one of the best UI front-end frameworks!
.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:
Something about CSS3 gradients That’s it. After reading it, everyone will definitely wonder, what are its main uses? There is a lot to say about this. The simplest one is to make a background. We can also use it to make some beautiful buttons, and we can also use it to make patterns. I will list several sample codes for making patterns here:
HTML code:
. Code
-
-
-
-
- li>
-
- 🎜>
-
-
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));
- }
效果:分享一个最好用的UI前端框架!
不错的效果吧,当然感兴趣的朋友可以到这里学习制作更多的不同效果。