CSS给错误了吗? [英] Is CSS giving error?

查看:83
本文介绍了CSS给错误了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最近的一次采访中,面试官被问到 CSS是否给错误?这个问题。

是否有一个解释器在CSS后面工作,阻止程序的执行?或者我们可以说CSS不会给出任何错误?我仍然对这个问题的答案感到困惑,因为面试官也没有说什么。

问题太广泛而不具体。
这就是我如何回答这个问题。


CSS是否提供错误?


取决于您正在查看的地点。
在IDE中?确定它会显示你验证错误。
在浏览器中?大多数浏览器倾向于忽略CSS验证错误,并继续执行其余的规则。另一个答案是@Kishan Choudhary在另一个回答中提到CSS只是指造型语言,语言不能自己提示错误。



Alt。问题:我们如何验证/调试/查找CSS中的错误?


我们可以说CSS不会给出任何错误?

这又取决于你正在看的地方。
在开发环境中?是的,几乎所有的Web IDE都能帮助你找到你的CSS错误。



在客户端浏览器中?并非如此,您可以打开浏览器控制台/开发人员工具(如果可用),并且可能存在日志错误,例如您在CSS中使用的图像的无效或无法访问的URL。这又是一个CSS语法还是验证错误?nope


是否有一个解释器在CSS后面工作,阻止
程序?


是的,每个浏览器都有一个内置的CSS解释器/标准,它是否阻止执行?不,大多数所有浏览器的正常行为都是忽略(不阻止解释和应用剩余的有效样式规则)CSS验证错误,并继续执行其余规则。



更新:W3指南处理CSS分析错误



级联样式表级别2修订1(CSS 2.1) strong>



4.2处理解析的规则错误


在某些情况下,用户代理必须忽略部分非法样式表。
这个规范定义了忽略意味着用户代理解析
非法部分(为了找到它的开始和结束),但
在其他情况下就好像它不在那里一样。 CSS 2.1预留
未来更新CSS所有属性:值组合和@ -keywords
,不包含以短划线或下划线开头的标识符。
实现必须忽略这些组合(除了将来更新CSS所引入的
之外)。



为了确保新的属性和现有的新值可以在将来添加属性


CSS语法模块级别3



2.2。错误处理


当CSS发生错误时,解析器会尝试正常恢复
在正常返回到
解析之前只扔掉最小量的内容。这是因为错误并不总是错误 - 新的
语法对于旧的解析器来说看起来是一个错误,并且
能够为语言添加新语法而不必担心
样式表包括它在旧版UA中完全被破解。



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.

解决方案

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.

这篇关于CSS给错误了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆