How to set gradient color in css

醉折花枝作酒筹
Release: 2023-01-05 16:08:02
Original
66295 people have browsed it

Method: 1. Use linear-gradient to set a linear gradient, the syntax "linear-gradient (angle, color, color)"; 2. Use radial-gradient to set a radial gradient, the syntax "radial-gradient (position) ,color,color)”.

How to set gradient color in css

The operating environment of this tutorial: Windows7 system, CSS3&&HTML5 version, Dell G3 computer.

CSS3 gradients allow you to display smooth transitions between two or more specified colors.

CSS3 defines two types of gradients:

  • Linear Gradients - Down/Up/Left/Right/Diagonally Directions

  • Radial Gradients - defined by their centers

In order to create a linear gradient, you must define at least two Color nodes. Color nodes are the colors you want to show a smooth transition. At the same time, you can also set a starting point and a direction (or an angle).

css setting linear gradient example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title></title> 
<style>
#grad1 {
    height: 200px;
    background: -webkit-linear-gradient(red, blue); /* Safari 5.1 - 6.0 */
    background: -o-linear-gradient(red, blue); /* Opera 11.1 - 12.0 */
    background: -moz-linear-gradient(red, blue); /* Firefox 3.6 - 15 */
    background: linear-gradient(red, blue); /* 标准的语法(必须放在最后) */
}
</style>
</head>
<body>
<h3>线性渐变 - 从上到下</h3>
<p>从顶部开始的线性渐变。起点是红色,慢慢过渡到蓝色:</p>
<div id="grad1"></div>
<p><strong>注意:</strong> Internet Explorer 9 及之前的版本不支持渐变。</p>
</body>
</html>
Copy after login

Rendering:

How to set gradient color in css

Recommended learning: css video tutorial

The above is the detailed content of How to set gradient color in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template