Home >Web Front-end >Front-end Q&A >How to set color gradient in css

How to set color gradient in css

藏色散人
藏色散人Original
2021-04-08 09:53:583283browse

How to set color gradients in css: 1. Use the "Linear Gradients" attribute in css3 to achieve linear color gradients; 2. Use the "Radial Gradients" attribute in css3 to achieve radial color gradients.

How to set color gradient in css

The operating environment of this article: Windows7 system, HTML5&&CSS3 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 Direction

  • Radial Gradients - defined by their center

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>

Rendering:

How to set color gradient in css

Related recommendations: "css3 Color Linear gradient attribute: smooth transition between several colors (complete code attached)

The above is the detailed content of How to set color gradient in css. For more information, please follow other related articles on the 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