Is CSS giving error?

后端 未结 19 1302
傲寒
傲寒 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:32

    @om. yes it can block your program but in very rear cases. For example if you relay on the width of the element and if you set a display:none to the element and did not make a case to return undefined your application will stuck because your parameter will not have a value.

    So it can prevent the execution with interference with other languages.

    However how other say in their answers, only css can trow a error for missing file or something like this, but it will not stop the execution of the application.

    But i have seen a problem when css property can make a jquery method not working properly and for this the jquery throw error and stop the execution of the application.

    0 讨论(0)
  • 2020-12-29 22:34

    Is CSS giving error ?

    Yes, any rule which cannot be understood by CSS parser will lead to an error. In general any data which cannot be handled by a system/program will lead to an error. But how the system finally handles that error is your question and it can be

    1. Ignore the error and continue to process.
    2. Halt the process.

    The CSS parser will not halt on an error. It just puts an error log to the console if it finds any invalid css property which cannot be parsed/ mentioned in specs and ignores(1) all the css-rule data till it finds next ;.

    As w3c.org doc says

    A UA must skip a declaration with an invalid property name or an invalid value.

    Here UA(User Agent) means browser in our case. So the invalid css keys/values has to be skipped and the browser vendor may choose to show error in devtools/firebug to help developers to fix it. Also it is browser vendor dependent to put error logs or not.

    0 讨论(0)
  • 2020-12-29 22:35

    Some browsers will report CSS errors in the console. Firefox comes to mind.

    <style> foo { bar: baz; } </style>
    

    results in the error:

    Unknown property 'bar'. Declaration dropped. css-error.html:2:11

    However, this will not "block execution of the program".

    To my knowledge, no similar feature exists in Chrome.

    0 讨论(0)
  • 2020-12-29 22:35

    html is a markup language, it does not contains errors so as css
    if there is something gone wrong, it tries to show what is right upto the mark
    css has no errors, but warnings as we can see in console that specific properties are invalid
    like using -webkit- while viewing in safari or mozilla

    0 讨论(0)
  • 2020-12-29 22:35

    Yeah, exactly right sometime CSS can also giving Error, But it is not through an error, instead of it stop the styling after where the Syntax has an error.

    CSS

    .myClass {
        color : red
        background-color : green;
    }
    

    This code will giving error, while the code will not execute in this case.

    0 讨论(0)
  • 2020-12-29 22:37

    NO, CSS never gives an error. You will not be able to see any error in console or anywhere caused by CSS.

    As CSS is just styling language and if something doesn't get styled as expected it will not be reported as error.

    To note that we have buggy CSS code we will have to look at the page and some elements on the page will be get rendered as expected. There are some tricks to Debug your CSS code.

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