CSS中,设置渐变色可以通过使用linear-gradient()函数来实现。
background: linear-gradient(direction, color-stop1, color-stop2, ...); 其中,direction表示渐变方向,可以使用角度值(如45deg)或关键字(如to bottom)来设置。color-stop表示渐变色的起始和结束颜色位置,可以使用颜色值或百分比值来设置。
以下是一些例子:
/* 从左上角到右下角渐变 */
background: linear-gradient(to bottom right, red, yellow);
/* 从中心向四周辐射渐变 */
background: linear-gradient(circle, red, yellow);
/* 渐变中间为白色 */
background: linear-gradient(to right, red, white 50%, blue);
/* 多段线性渐变 */
background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); 通过这些设置,我们可以创建出漂亮的渐变效果,使页面更加生动有趣。