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)”.
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>
Rendering:
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!