search
HomeWeb Front-endCSS Tutorial'CSS3 Practical Combat' Notes--Gradient Design (1)

Compared with image gradients, the biggest advantage of CSS-based gradients is that they are easy to modify and support stepless scaling, making the transition more natural. Currently, only browsers based on Webkit and Gecko engines can implement CSS gradients. The Opera browser based on the Presto engine does not support gradients for the time being. Although IE based on Trident can achieve it through filters, it is not recommended.

CSS gradient design for Webkit engine (Safari 4 and above)

Basic syntax:

-webkit-gradient(,[,]?,[ ,]?[,]*)

Parameter description:

: Define the gradient type, including linear gradient (linear) and radial gradient (radial).

: Define the starting point and end point coordinates of the gradient, that is, the x-axis and y-axis coordinates where the gradient starts to be applied, and the coordinates where the gradient ends. This parameter supports numerical values, percentages and keywords, such as (0, 0) or (left, top), etc. Keywords include top, bottom, left and right.

: When defining a radial gradient, it is used to set the length of the radial gradient. This parameter is a numerical value.

: Define gradient color and step size. It includes three types of values, namely the starting color, defined using the from (color value) function; the ending color, defined using the to (color value) function: the color step, defined using color-stop (value, color value). color-stop() contains two parameter values. The first parameter value is a numerical value or percentage value, the value range is 0~1.0 (or 0%~100%), and the second parameter value represents any color value.

Basic usage of linear gradient:

/*Simple linear gradient background color, from top to bottom, from blue to red gradient display*/background: -webkit-gradient(linear, left top, left bottom, from(blue ), to(red));

Demonstration effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*From top to middle, then from middle to bottom, from blue to green, then to red gradient display*/background: -webkit -gradient(linear, left top, left bottom, from(blue), to(red), color-stop(50%, green));

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*Design double gradient , from top to bottom, first from blue to white, then from black to red */background: -webkit-gradient(linear, left top, left bottom, from(blue), to(red),color -stop(0.5, #fff), color-stop(0.5, #000));

Demonstration effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*Design multiple gradient effects by setting different step values, starting from the top To the bottom, first the gradient is from blue to white, then from Baise to black, and finally from black to red. */background: -webkit-gradient(linear, left top, left bottom, from(blue), to( red),color-stop(0.4, #fff), color-stop(0.6, #000));

Demonstration effect:

CSS3 Practical Combat Notes--Gradient Design (1)

Summary: The color-stop() function contains two parameter values, The first parameter value specifies the corner mark position, and the second parameter specifies the color mark color. A gradient can contain multiple color stops. The position value is a decimal between 0 and 1, or a percentage between 0 and 100%, specifying the position proportion of the color stop.

Basic usage of radial gradient

/* Concentric circles (center coordinates are 200, 100), inner circle radius is 10, outer circle radius is 100, inner circle is smaller than outer circle radius, from inner circle red to outer circle green Radial gradient, the outer circle radius is displayed in green, and the inner circle is displayed in red*/background: -webkit-gradient(radial, 200 100, 10, 200 100, 100, from(red), to(green));

Effect display:

CSS3 Practical Combat Notes--Gradient Design (1)

/* Concentric circles (center coordinates are 200, 100), inner circle radius is 100, outer circle radius is 100, inner circle is smaller than outer circle radius, from inner circle red to outer circle green Radial gradient. When the radius of the inner circle and the outer circle are equal, the gradient is invalid*/background: -webkit-gradient(radial, 200 100, 100, 200 100, 100, from(red), to(green));

Demo effect :

CSS3 Practical Combat Notes--Gradient Design (1)

/* Concentric circles (center coordinates are 200, 100), inner circle radius is 100, outer circle radius is 10, inner circle is larger than outer circle radius, radial gradient from inner circle red to outer circle green , exceeding the inner circle radius is displayed in red, and the outer circle is displayed in green*/
background: -webkit-gradient(radial, 200 100, 100, 200 100, 10, from(red), to(green));

Demo Effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/* For non-concentric circles, if the distance between the center of the inner circle and the center of the outer circle is less than the difference in the radius of the two circles, the effect shown above will be displayed, showing a tapered radial gradient effect. The sharpness of the cone is proportional to the distance between the centers of the two circles*/background: -webkit-gradient(radial, 120 100, 10, 200 100, 100, from(red), to(green));

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/* Concentric circles, add a blue color mark at 90% of the position from the inner circle to the outer circle, that is, within the distance from the outer ring, and design a multi-layer radial gradient, as shown in the picture below. */background: -webkit-gradient(radial, 200 100, 10, 200 100, 100, from(red), to(green), color-stop(90%, blue));

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*By setting the color value of the to() function to be transparent, you can design a divergent circular effect*/background: -webkit-gradient(radial, 200 100, 10, 200 100, 90, from(red) , to(rgba(1,159,98,0)));

Demonstration effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*By setting the color value of the to() function to transparent and designing similar colors, you can design a spherical effect* /background: -webkit-gradient(radial, 180 80, 10, 200 100, 90, from(#00C), to(rgba(1,159,98,0)), color-stop(98%, #0CF));

Demonstration effect:

CSS3 Practical Combat Notes--Gradient Design (1)

/*By defining multiple radial gradients for the background image, you can design multiple bubble effects, as shown below*/background: -webkit-gradient(radial, 45 45, 10 , 52 50, 30, from(#A7D30C), to(rgba(1,159,98,0)), color-stop(90%, #019F62)), -webkit-gradient(radial, 105 105, 20, 112 120 , 50, from(#ff5f98), to(rgba(255,1,136,0)), color-stop(75%, #ff0188)), -webkit-gradient(radial, 95 15, 15, 102 20, 40, from(#00c9ff), to(rgba(0,201,255,0)), color-stop(80%, #00b5e2)), -webkit-gradient(radial, 300 110, 10, 300 100, 100, from(#f4f201) , to(rgba(228, 199,0,0)), color-stop(80%, #e4c700)); -webkit-background-origin: padding-box; -webkit-background-clip: content-box;

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)

Gradient application defines the border of the gradient effect

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webkit引擎的渐变实现方法</title>
<style type="text/css">
div {
 border-width: 20px;
 width: 400px;
 height: 200px;
 margin: 20px;
 -webkit-border-image: -webkit-gradient(linear, left top, left bottom, from(#00abeb), to(#fff), color-stop(0.5, #fff), color-stop(0.5, #66cc00)) 20;
}
</style>
</head>
 
<body>
<div></div>
</body>
</html>

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)

Define the fill content effect

Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webkit引擎的渐变实现方法</title>
<style type="text/css">
.div1 {
 width:400px;
 height:200px;
 border:10px solid #A7D30C;
 background: -webkit-gradient(linear, left top, left bottom, from(#00abeb), to(#fff), color-stop(0.5, #fff), color-stop(0.5, #66cc00));
 float:left;
}
.div1::before {
 width:400px;
 height:200px;
 border:10px solid #019F62;
 content: -webkit-gradient(radial, 200 100, 10, 200 100, 100, from(#A7D30C), to(rgba(1, 159, 98, 0)), color-stop(90%, #019F62));
 display: block;
}
</style>
</head>
 
<body>
<div class="div1">透视框</div>
</body>
</html>

Display effect:

CSS3 Practical Combat Notes--Gradient Design (1)

Define list icon

   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Webkit引擎的渐变实现方法</title>
<style type="text/css">
ul {
 list-style-image: -webkit-gradient(radial, center center, 4, center center, 8, from(#ff0000), to(rgba(0, 0, 0, 0)), color-stop(90%, #dd0000))
}
</style>
</head>
 
<body>
<ul>
 <li>新闻列表项1</li>
 <li>新闻列表项2</li>
 <li>新闻列表项3</li>
 <li>新闻列表项4</li>
</ul>
</body>
</html>

Demo effect:

CSS3 Practical Combat Notes--Gradient Design (1)


More "CSS3 Practical" Notes - Gradient Design (1) related articles please Follow 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
Two Images and an API: Everything We Need for Recoloring ProductsTwo Images and an API: Everything We Need for Recoloring ProductsApr 15, 2025 am 11:27 AM

I recently found a solution to dynamically update the color of any product image. So with just one of a product, we can colorize it in different ways to show

Weekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsWeekly Platform News: Impact of Third-Party Code, Passive Mixed Content, Countries with the Slowest ConnectionsApr 15, 2025 am 11:19 AM

In this week's roundup, Lighthouse sheds light on third-party scripts, insecure resources will get blocked on secure sites, and many country connection speeds

Options for Hosting Your Own Non-JavaScript-Based AnalyticsOptions for Hosting Your Own Non-JavaScript-Based AnalyticsApr 15, 2025 am 11:09 AM

There are loads of analytics platforms to help you track visitor and usage data on your sites. Perhaps most notably Google Analytics, which is widely used

It's All In the Head: Managing the Document Head of a React Powered Site With React HelmetIt's All In the Head: Managing the Document Head of a React Powered Site With React HelmetApr 15, 2025 am 11:01 AM

The document head might not be the most glamorous part of a website, but what goes into it is arguably just as important to the success of your website as its

What is super() in JavaScript?What is super() in JavaScript?Apr 15, 2025 am 10:59 AM

What's happening when you see some JavaScript that calls super()?.In a child class, you use super() to call its parent’s constructor and super. to access its

Comparing the Different Types of Native JavaScript PopupsComparing the Different Types of Native JavaScript PopupsApr 15, 2025 am 10:48 AM

JavaScript has a variety of built-in popup APIs that display special UI for user interaction. Famously:

Why Are Accessible Websites so Hard to Build?Why Are Accessible Websites so Hard to Build?Apr 15, 2025 am 10:45 AM

I was chatting with some front-end folks the other day about why so many companies struggle at making accessible websites. Why are accessible websites so hard

The `hidden` Attribute is Visibly WeakThe `hidden` Attribute is Visibly WeakApr 15, 2025 am 10:43 AM

There is an HTML attribute that does exactly what you think it should do:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment