简体   繁体   English

带有图像和扩展渐变的背景的CSS属性值无效

[英]Invalid CSS property value for background with image and extension gradient

Chrome has started to warn me about my legacy gradients: Chrome已开始向我发出有关遗留渐变的警告:

Invalid CSS property value: right no-repeat url('../Images/Logo_white.png'), 
-moz-linear-gradient(bottom, #899fa6, #3e545c) 

It is only for the extensions for o, moz and ms: 它仅适用于o,moz和ms的扩展:

background: right no-repeat url('../Images/CompanyLogo.png'), 
-moz-linear-gradient(bottom, #000000, #ffffff);

The one for webkit is fine: webkit的那个很好:

background: right no-repeat url('../Images/CompanyLogo.png'), 
-webkit-linear-gradient(bottom, #000000, #ffffff);

Am I doing something wrong? 难道我做错了什么?

The extension-gradients do not generate a warning when they are used alone as opposed to being combined with an image. 扩展渐变在单独使用时不会生成警告,而不是与图像组合。

The reason why you're getting warnings from Chrome's dev tool is because the values are indeed invalid for Chrome. 您从Chrome的开发工具收到警告的原因是因为Chrome的值确实无效。 However, this should not alarm you because this is the way that it was designed. 但是,这不应该让你感到惊恐,因为这是它的设计方式。

In CSS, if something is defined incorrectly or not recognized by the browser then it is simply passed over, nothing is done and it only gives a warning not an error. 在CSS中,如果某些内容被错误地定义或者浏览器无法识别,那么它只是简单地传递,没有做任何事情,它只会发出警告而不是错误。 This behavior is exactly what allows vendor prefixes to work. 此行为正是允许供应商前缀工作的原因。 Take for example your own situation: 以你自己的情况为例:

background: right no-repeat url('../Images/CompanyLogo.png'), 
-moz-linear-gradient(bottom, #000000, #ffffff);

background: right no-repeat url('../Images/CompanyLogo.png'), 
-webkit-linear-gradient(bottom, #000000, #ffffff);

background: right no-repeat url('../Images/CompanyLogo.png'), 
linear-gradient(bottom, #000000, #ffffff);

Chrome goes through each background property and sees which one it can interpret. Chrome浏览每个background属性并查看它可以解释的属性。 It can't interpret the first gradient because it doesn't recognize -moz- like Firefox does. 它无法解释第一个渐变,因为它不像Firefox那样识别-moz- It can interpret the second one because it has a -webkit- prefix. 可以解释第二个,因为它有一个-webkit-前缀。 It can also interpret the third background because Chrome supports un-prefixed CSS gradients. 可以解释第三个背景,因为Chrome支持无前缀CSS梯度。

Since more than one CSS attributes affect the same thing ( background ), the most recent one listed (the unprefixed version) will be used. 由于多个CSS属性会影响相同的事物( background ),因此将使用列出的最新属性(未加前缀的版本)。 A warning will display for the un-interpretted first background , but it will have no effect on the project. 将显示未解释的第一个background的警告,但它不会对项目产生任何影响。

Yes, warnings should be looked at and analyzed, generally treated as errors . 是的, 应该查看和分析警告,通常将其视为错误 With that being said, the case you bring up about browser prefixes is the correct way of doing it, so the warnings should be accepted. 话虽如此,你提出的关于浏览器前缀的案例是正确的做法,所以应该接受警告。 In a perfect world they would not show up at all, they'd understand that it is meant for another browser, but there is no reason to worry about it because it is indeed the correct way of doing it 在一个完美的世界中,他们根本不会出现,他们会明白它是为另一个浏览器而设,但是没有理由担心它,因为它确实是这样做的正确方法

But then again, this is all semi irrelevant because all major browsers support CSS gradients unprefixed . 但话说回来,这一切都是半无关紧要的,因为所有主流浏览器都支持CSS渐变无前缀

I found this bug on Chrome Developer Tools: 我在Chrome开发者工具上发现了这个错误:

http://code.google.com/p/chromium/issues/detail?id=309982 http://code.google.com/p/chromium/issues/detail?id=309982

Seems like they will temporarily disable CSS warnings because of too many false positives (including valid CSS for legacy browsers, if we are to go by the ticket author) until they have fixed it. 看起来他们会暂时禁用CSS警告,因为误解太多(包括旧版浏览器的有效CSS,如果我们要通过票证作者),直到他们修复它。

Chances are that these warnings are part of those false positives. 这些警告可能是这些误报的一部分。 I will monitor the issue. 我会监控这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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