Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is CSS giving error?

Tags:

html

dom

css

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 execution of the program? Or can we say that CSS does not give any error? I am still confused as to what is the answer to this question because the interviewer also did not say anything.

like image 640
om_jaipur Avatar asked Oct 16 '15 12:10

om_jaipur


People also ask

How do I fix CSS errors?

Replace broken CSS files with those ones that return 200 HTTP status codes or remove them. What else should be considered to fix the problem: Try to clear your browser's cache. If the page returns 5xx errors, the problem may be on the server: it's not handling the traffic because it's too slow or misconfigured.

How does CSS determine errors?

A quick way to find errors in CSS code is to install the Web Developer tool bar add-on and use the validator through the tools drop down. What's cool about this tool is you can quickly validate local files too as it will automatically upload them to the W3C validator.

How do I fix parsing error in CSS?

When you get parse errors as you copy CSS from a different source, you first need to check the final semicolon. The easiest way to fix these errors is to paste the CSS code into an editor like Notepad++. You can use the editor to find or replace these errors.

What is error in HTML?

HTML Error MessagesWhen a browser requests a service from a web server, an error might occur, and the server might return an error code like "404 Not Found". It is common to name these errors HTML error messages. But these messages are something called HTTP status messages.


2 Answers

CSS itself will not give an error, however CSS which has an error in its syntax will not render correctly. The browser may not be able to understand what is meant at a given point, and therefore not be able to format the page correctly.

There's also a difference in CSS being syntactically correct, where everything is properly enclosed and lines terminated, and it being standards compliant according to the W3C specification.

EDIT : (example for syntax correctness and standards compliance) The following is an example of syntactically correct CSS, which won't fail validation on the W3C CSS Validator:

p.my-class {   color : red;   -moz-border-radius : 3px; } 

Whilst this is technically valid CSS, according to the vendor specific extensions section of the CSS 2.1 syntax, they should be avoided. It's the initial dash or underscore which lets them be valid.

like image 155
gabe3886 Avatar answered Sep 19 '22 02:09

gabe3886


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.

like image 35
Deshan Avatar answered Sep 19 '22 02:09

Deshan