Is CSS giving error?

后端 未结 19 1301
傲寒
傲寒 2020-12-29 21:35

At a recent interview I was asked the question \"Is CSS giving error?\" by the interviewer.

Is there an interpreter working behind CSS which blocks

相关标签:
19条回答
  • I think the "Is CSS giving error?" statement is ambiguous, but let's first take a look at this link (CSS 2.1 Specification), jump to 4.2 Rules for handling parsing errors

    The specification explicitly specifies how parsing errors should be ignored, in fact, it says:

    This specification
    defines ignore to mean that the user agent parses the illegal part (in order to find
    its beginning and end), but otherwise acts as if it had not been there
    

    In fact, in same cases it even specifies how to turn an invalid piece of css into a valid one:

    User agents must close all open constructs (for example: blocks, parentheses,
    brackets, rules, strings, and comments) at the end of the stylesheet. For
    example:
    
    @media screen {
      p:before { content: ’Hello
    
    would be treated the same as:
    
    @media screen {
      p:before { content: ’Hello’; }
    }
    

    So looking from this perspective, CSS never "gives" errors, because any errors will be effectively parsed and fixed or ignored, but will never stop execution of the rules nor the parser.

    However, if you have one developer talking to another in front of an IDE, I think it would be fair enough to ask "Is the CSS giving errors" referring to the IDE's messages and in fact, if we look at a CSS parser project we can clearly see in the documentation that the parser can give error messages, it's just browsers that were directly instructed to ignore errors.

    0 讨论(0)
提交回复
热议问题