Is CSS giving error?

后端 未结 19 1299
傲寒
傲寒 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条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-29 22:14

    I think the question is too broad and not specific. This is how I would have answered the question.

    Is CSS giving error ?

    Depends on the place you are looking at. In a IDE? sure it will show you validation errors. In browser? Most browsers tend to ignore CSS validation errors and continue with rest of the rules.Again as @Kishan Choudhary mentioned in another answer "CSS" refers just the styling language and languages cannot prompt you errors by themselves.

    Alt. Question: How can we validate/debug/find errors in a CSS?

    Can we say that CSS does not give any error?

    Again it depends on the place you are looking at. In development environment? Yes almost all web IDEs will help you to find your CSS mistakes.

    In Client browser? Not so much,You can open browser console/developer tool if available and there might be logs errors, for example invalid or unreachable URLs of images you have used in CSS. Again is it a CSS syntax or validation error?nope

    Is there an interpreter working behind CSS which blocks execution of the program?

    Yes every browser has an inbuilt CSS interpreter/parser following W3C standards and does it like to block execution?No,normal behavior of all most all browsers is to that ignore (not to block interpreting and applying remaining valid style rules) CSS validation errors and continue with rest of the rules.

    Update: W3 Guidelines Handling CSS Parsing Errors

    Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification

    4.2 Rules for handling parsing errors

    In some cases, user agents must ignore part of an illegal style sheet. 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. CSS 2.1 reserves for future updates of CSS all property:value combinations and @-keywords that do not contain an identifier beginning with dash or underscore. Implementations must ignore such combinations (other than those introduced by future updates of CSS).

    To ensure that new properties and new values for existing properties can be added in the future.

    CSS Syntax Module Level 3

    2.2. Error Handling

    When errors occur in CSS, the parser attempts to recover gracefully, throwing away only the minimum amount of content before returning to parsing as normal. This is because errors aren’t always mistakes - new syntax looks like an error to an old parser, and it’s useful to be able to add new syntax to the language without worrying about stylesheets that include it being completely broken in older UAs.

提交回复
热议问题