简体   繁体   English

CSS:值错误:背景图像是不正确的运算符)(验证失败)

[英]CSS: Value Error : background-image is an incorrect operator ) (validation fails)

Why is the following CSS invalid according to https://validator.w3.org/nu/#textarea (check the CSS box), yet browsers render the code just fine?为什么根据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);
}

Value Error: background-image is an incorrect operator值错误:背景图像是不正确的运算符

 .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>

Looks like the validator is failing when you use multi-position color stops https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient()#gradient_with_multi-position_color_stops当您使用多位置颜色停止时,验证器似乎失败https://developer.mozilla.org/en-US/docs/Web/CSS/linear-gradient()#gradient_with_multi-position_color_stops

If you remove the second position for things like #ff5722 10% 15% (try something like #ff5722 15% ) it doesn't show the error.如果您删除第二个 position 之类的东西#ff5722 10% 15% (尝试类似#ff5722 15% )它不会显示错误。

I believe it's an issue with the validator and not with your code though, it's valid CSS, it even fails with code copied straight from MDN.我相信这是验证器的问题,而不是您的代码的问题,它是有效的 CSS,它甚至因直接从 MDN 复制的代码而失败。

If you really want to remove that validation error, you can split the color stop in 2 instead of using multi stops like #ff5722 10%, #ff5722 15%如果您真的想消除该验证错误,您可以将颜色停止拆分为 2,而不是使用多个停止,如#ff5722 10%, #ff5722 15%

it's related to the double color stops #ff5722 10% 15% .它与双色停止有关#ff5722 10% 15% The validator seems to be not up to date with this new syntax.验证器似乎不是最新的这种新语法。 You can update your code and use:您可以更新代码并使用:

.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM