[英]CSS: Value Error : background-image is an incorrect operator ) (validation fails)
为什么根据https://validator.w3.org/nu/#textarea (检查CSS
框),以下 CSS 无效,但浏览器渲染代码就好了?
.color {
background-image: linear-gradient(to right, rgb(248, 27, 27) 7%, #ff5722 10% 15%, #43a047 50% 60%, #7e57c2 92%, indigo);
}
值错误:背景图像是不正确的运算符
.color { background-image: linear-gradient(to right, rgb(248, 27, 27) 7%, #ff5722 10% 15%, #43a047 50% 60%, #7e57c2 92%, indigo); background-clip: content-box; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } p { background-image: linear-gradient(to left, violet, indigo, blue, green, yellow, orange, red); }
<p class="color">testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing</p> <p>testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content testing content</p>
当您使用多位置颜色停止时,验证器似乎失败https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient()#gradient_with_multi-position_color_stops
如果您删除第二个 position 之类的东西#ff5722 10% 15%
(尝试类似#ff5722 15%
)它不会显示错误。
我相信这是验证器的问题,而不是您的代码的问题,它是有效的 CSS,它甚至因直接从 MDN 复制的代码而失败。
如果您真的想消除该验证错误,您可以将颜色停止拆分为 2,而不是使用多个停止,如#ff5722 10%, #ff5722 15%
它与双色停止有关#ff5722 10% 15%
。 验证器似乎不是最新的这种新语法。 您可以更新代码并使用:
.color {
background-image: linear-gradient(to right, rgb(248, 27, 27) 7%, #ff5722 10%, #ff5722 15%, #43a047 50%, #43a047 60%, #7e57c2 92%, indigo);
background-clip: content-box;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
p {
background-image: linear-gradient(to left, violet, indigo, blue, green, yellow, orange, red);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.