- 1
CSS gradients allow you to create smooth transitions between two or more specified colors. There are three main types of gradients in CSS: linear gradients, radial gradients, and conic gradients1.
Linear Gradients
Linear gradients transition colors along a straight line. You can define at least two color stops and set a direction or angle for the gradient.
Syntax
background-image: linear-gradient(direction, color-stop1, color-stop2, ...);Examples
Top to Bottom (default)
#grad {background-image: linear-gradient(red, yellow);}Left to Right
#grad {background-image: linear-gradient(to right, red, yellow);}Diagonal (Top Left to Bottom Right)
#grad {background-image: linear-gradient(to bottom right, red, yellow);}Using Angles
#grad {background-image: linear-gradient(180deg, red, yellow);}Multiple Color Stops
#grad {background-image: linear-gradient(red, yellow, green);}Rainbow Background
#grad {background-image: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);} CSS Gradients - W3Schools
使用 CSS 渐变 - CSS:层叠样式表 | MDN - MDN Web Docs
Using CSS gradients - CSS: Cascading Style Sheets | MDN - MDN …
ColorSpace - CSS Gradient Color Generator
CSS3 渐变(Gradients) - 菜鸟教程
background-image: linear-gradient (angle, color-stop1, color-stop2); 角度是指水平线和渐变线之间的角度,逆时针方向计算。 换句话说,0deg 将创建一个从下到上的渐变,90deg 将创建一个从左到右的渐变。
- 其他用户还问了以下问题
CSS linear-gradient() Function - W3Schools
Gradient Generator - CSS gradients made easy - ColorGradient
css 使用 background: linear-gradient 实现渐变色 - CSDN博客
CSS Gradient Generator - Make and generate beautiful …
Use this online tool to make linear, radial, conic or text gradients with different colors and directions. Learn more about CSS gradients, their types, properties and browser compatibility.