使用 CSS 设置颜色停止点的位置
cssweb developmentfront end technology更新于 2025/12/16 7:40:17
颜色停止点的位置可以设置为百分比或绝对长度。例如,对于线性渐变
background-image: linear-gradient( rgb(61, 255, 2) 40%, rgb(0, 174, 255) 80%, rgb(255, 29, 29) 20% );
以下是使用 CSS 设置线性渐变中颜色停止点位置的代码 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
.even {
height: 100px;
background-image: linear-gradient(
rgb(61, 255, 2),
rgb(0, 174, 255),
rgb(255, 29, 29)
);
}
.uneven {
height: 100px;
background-image: linear-gradient(
rgb(61, 255, 2) 40%,
rgb(0, 174, 255) 80%,
rgb(255, 29, 29) 20%
);
}
</style>
</head>
<body>
<h1>Linear gradient location color stops</h1>
<h3>Evenly Spaced</h3>
<div class="even"></div>
<h3>Unevenly Spaced</h3>
<div class="uneven"></div>
</body>
</html>
输出
上述代码将产生以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

