jQuery causes Firefox box-sizing warnings

送分小仙女□ 提交于 2019-12-19 12:25:55

问题


I have the WebDeveloper extension and I got a CSS warning so I went to investigate it. The warning is 3 of the following:

Warning: Unknown property 'box-sizing'.  Declaration dropped.
Line: 0

Then I made a blank file and noticed it wasn't there. A few minutes later I found a reproducible cause: including the jQuery 1.9.1 script!

What can or should I do? I want to use jquery but I find it a bit annoying that I'll forever see CSS warnings in my toolbar.

<!DOCTYPE html>
<html>
<head></head>
<body>
<div>Empty</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</body>
</html>

回答1:


Options

  1. Use jQuery 1.7.2.
  2. Raise the issue with the jQuery team and hope for a fix (or provide one yourself).
  3. Use Firebug instead of WebDeveloper (which may or may not help).
  4. Ignore it.

As long as the page renders correctly, I believe this is a warning you can safely ignore, even if you're building a website that strictly requires validating the CSS.

The warnings should go away as soon as Firefox has full support for box-sizing (without requiring the -moz- prefix), but that won't happen until some version after Firefox 21.

Background info

The warning arises from the different syntaxes needed for certain CSS styles. To support all browsers, you generally have to specify all of the various syntaxes. Browsers will ignore the ones they don't recognize.

In the case of box-sizing, Firefox requires the -moz- prefix, early versions of Safari Mobile and the Android browser require the -webkit- prefix, and other browsers require no prefix at all:

-webkit-box-sizing: content-box;
   -moz-box-sizing: content-box;
        box-sizing: content-box;

A similar issue arises when adding a linear gradient, in this case caused by the value rather than the property name:

background-image: -webkit-linear-gradient(top, #444, #999);
background-image:    -moz-linear-gradient(top, #444, #999);
background-image:     -ms-linear-gradient(top, #444, #999);
background-image:      -o-linear-gradient(top, #444, #999);
background-image:         linear-gradient(top, #444, #999);

When warnings arise from the different syntaxes used, it's typically a case of the validator or error console not being smart enough to recognize a real problem from a harmless one that's often unavoidable. And to be fair, it is in fact identified as a warning, not an error.

Additional info

Newer versions of jQuery make use of the box-sizing style for internal purposes. jQuery 1.8.0 only produces a single box-sizing warning, and jQuery 1.7.2 produces none.

jQuery may be using it in a slightly-careless way -- without first testing if there's some type of support for it -- but without doing any actual harm. If so, if enough people complain about it to the jQuery team, the jQuery code could potentially be refactored to address this (at the cost of jQuery running a tiny bit slower).

If the warning were about -moz-box-sizing rather than box-sizing, that would more likely suggest a possible bug with Firefox rather than a minor issue with jQuery.




回答2:


According to the jQuery folks this is a Firefox issue and they can't do anything about it. As of Firefox 27(beta) it is still happening. See: http://bugs.jquery.com/ticket/13569



来源:https://stackoverflow.com/questions/15306923/jquery-causes-firefox-box-sizing-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!