How to use css radial gradient: first create an HTML sample file; then create a div block; finally add the css style as "background:radial-gradient()" to achieve the radial gradient effect. .
The operating environment of this tutorial: Windows7 system, HTML5&&CSS3 version. This method is suitable for all brands of computers.
Recommended: "css video tutorial"
Radial gradients: From the starting point to the end point, the color performs a circular gradient from the inside to the outside.
Syntax
background:radial-gradient(center,shape size,start-color,……,last-color);
Radial Gradient-Set Shape
Syntax:
background:radial-gradient(shape,start-color,……,last-color);
Description:
shape value can take two
circle——circle
ellipse——ellipse (default)
radial gradient-size keyword
size keyword is OK to end The position of the color. The default value is farthest-corner.
Syntax
background:radial-gradient(size,start-color,……,last-color);
size value is the following four keywords:
closest-side: the closest side
farthest-side: the farthest side
closest-corner: closest corner
farthest-corner: farthest corner
Example:
div { width: 300px; height: 200px; /* Safari 5.1 - 6.0 */ background: -webkit-radial-gradient(30% 70%, farthest-side, blue, green, yellow, black); /* Opera 11.6 - 12.0 */ background: -o-radial-gradient(30% 70%, farthest-side, blue, green, yellow, black); /* Firefox 3.6 - 15 */ background: -moz-radial-gradient(30% 70%, farthest-side, blue, green, yellow, black); /* 标准的语法 */ background: radial-gradient(30% 70%, farthest-side, blue, green, yellow, black); }
Radial Gradient-Circle Center Position
Grammar:
background:radial-gradient(level-percent vertical-percent,start-color,……,last-color);
Note: The standard syntax at the center of the circle is currently poorly supported by mainstream browsers, so you need to pay attention to adding the browser prefix.
General usage:
-webkit-background:radial-gradient(level-percent vertical-percent,start-color,……,last-color); -o-background:radial-gradient(level-percent vertical-percent,start-color,……,last-color); -moz-background:radial-gradient(level-percent vertical-percent,start-color,……,last-color); background:radial-gradient(level-percent vertical-percent,start-color,……,last-color);
Thinking: 1. What is the meaning of the percentage value behind the color in the gradient?
3-12 Programming exercises
Friends, I have learned CSS3 radial gradient. According to the renderings, I added the code to achieve:
(1) Taking the center (60% 40%) as the starting point, set the center of the circle to the nearest edge, the roundest edge, Four radial gradient effects: closest corner and roundest corner.
(2) The shape of the radial gradient is a circle
(3) The colors from the inside to the outside are red, yellow, green, and blue
The effect picture is as follows
Task
Set the background color radial gradient for each of the four elements
(1)Set the radial gradient size to the nearest edge , farthest edge, closest corner, farthest corner
(2)The center of the gradient is 60% and 40%
(3)The shape of the gradient is a circle
(4) The gradient colors are red, yellow, green, and blue from the inside to the outside.
Reference code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>径向渐变</title> <style> div { width: 200px; height: 300px; float: left; margin: 100px 0 0 100px; } /* 补充代码,分别写出4个元素的背景渐变效果 */ .div1 { background: -webkit-radial-gradient(60% 40%,closest-side circle, red,yellow,green,blue); /* Opera 11.6 - 12.0 */ background: -o-radial-gradient(60% 40%,closest-side circle, red,yellow,green,blue); /* Firefox 3.6 - 15 */ background: -moz-radial-gradient(60% 40%,closest-side circle, red,yellow,green,blue); /* 标准的语法 */ background: radial-gradient(60% 40%,closest-side circle, red,yellow,green,blue); } .div2 { background: -webkit-radial-gradient(60% 40%,farthest-side circle, red,yellow,green,blue); /* Opera 11.6 - 12.0 */ background: -o-radial-gradient(60% 40%,farthest-side circle, red,yellow,green,blue); /* Firefox 3.6 - 15 */ background: -moz-radial-gradient(60% 40%,farthest-side circle, red,yellow,green,blue); /* 标准的语法 */ background: radial-gradient(60% 40%,farthest-side circle, red,yellow,green,blue); } .div3 { background: -webkit-radial-gradient(60% 40%,closest-corner circle, red,yellow,green,blue); /* Opera 11.6 - 12.0 */ background: -o-radial-gradient(60% 40%,closest-corner circle, red,yellow,green,blue); /* Firefox 3.6 - 15 */ background: -moz-radial-gradient(60% 40%,closest-corner circle, red,yellow,green,blue); /* 标准的语法 */ background: radial-gradient(60% 40%,closest-corner circle, red,yellow,green,blue); } .div4 { background: -webkit-radial-gradient(60% 40%,farthest-corner circle, red,yellow,green,blue); /* Opera 11.6 - 12.0 */ background: -o-radial-gradient(60% 40%,farthest-corner circle, red,yellow,green,blue); /* Firefox 3.6 - 15 */ background: -moz-radial-gradient(60% 40%,farthest-corner circle, red,yellow,green,blue); /* 标准的语法 */ background: radial-gradient(60% 40%,farthest-corner circle, red,yellow,green,blue); } </style> </head> <body> <div></div> <div></div> <div></div> <div></div> </body> </html>
Radial Gradual-Repeating Gradient
background:repeating-radial-gradient(color1 length|percent,color2 length|percent,……);
3-14 Programming Exercise
Friends, we have learned CSS3 Radial Repeating gradients in gradients, next, write the code based on the renderings to implement repeated radial gradients of multiple rainbow balls with the center of the element as the origin.
(1) The 7 colors of the rainbow are required. The value range starts from 0% and increases by 5% at a time. For example, red is 0%, orange is 5%, yellow is 10%, and so on
(2) Tips: The color of the rainbow ball can be expressed in English words
(3) The rendering is as follows:
Reference code:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"> <title>径向渐变</title> <style> div { width: 400px; height: 400px; /* 补充代码 */ background: -webkit-repeating-radial-gradient(closest-side circle, red 0%,orange 5%,yellow 10%,green 15%,blue 20%,indigo 25%,purple 30%); /* Opera 11.6 - 12.0 */ background: -o-repeating-radial-gradient( closest-side circle,red 0%,orange 5%,yellow 10%,green 15%,blue 20%,indigo 25%,purple 30%); /* Firefox 3.6 - 15 */ background: -moz-repeating-radial-gradient(closest-side circle,red 0%,orange 5%,yellow 10%,green 15%,blue 20%,indigo 25%,purple 30%); /* 标准的语法 */ background: repeating-radial-gradient( closest-side circle, red 0%,orange 5%,yellow 10%,green 15%,blue 20%,indigo 25%,purple 30%); } </style> </head> <body> <div></div> </body> </html>
The above is the detailed content of How to use css radial gradient. For more information, please follow other related articles on the PHP Chinese website!

In this week's roundup: Firefox gains locksmith-like powers, Samsung's Galaxy Store starts supporting Progressive Web Apps, CSS Subgrid is shipping in Firefox

In this week's roundup: Internet Explorer finds its way into Edge, Google Search Console touts a new speed report, and Firefox gives Facebook's notification

You’re probably already at least a little familiar with CSS variables. If not, here’s a two-second overview: they are really called custom properties, you set

Building websites is programming. Writing HTML and CSS is programming. I am a programmer, and if you're here, reading CSS-Tricks, chances are you're a

Here's what I'd like you to know upfront: this is a hard problem. If you've landed here because you're hoping to be pointed at a tool you can run that tells

Picture-in-Picture made its first appearance on the web in the Safari browser with the release of macOS Sierra in 2016. It made it possible for a user to pop

Gatsby does a great job processing and handling images. For example, it helps you save time with image optimization because you don’t have to manually

I learned something about percentage-based (%) padding today that I had totally wrong in my head! I always thought that percentage padding was based on the


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)