在 CSS 中使用角度设置线性渐变的方向
cssweb developmentfront end technology更新于 2025/12/10 17:48:17
为了更好地控制渐变的方向,请按以下语法定义角度 −
background-image: linear-gradient(angle, color-stop1, color-stop2);
以下是在 CSS 中使用角度设置线性渐变方向的代码 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
div {
height: 200px;
width: 300px;
display: inline-block;
margin-right: 10px;
}
.linearGradient {
background-image: linear-gradient(90deg, rgb(255, 0, 200), yellow);
}
.linearGradient1 {
background-image: linear-gradient(-90deg, rgb(255, 0, 200), yellow);
}
</style>
</head>
<body>
<h1>Linear Gradient direction using angles</h1>
<div class="linearGradient"></div>
<div class="linearGradient1"></div>
</body>
</html>
输出
上述代码将产生以下输出 −

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

