为什么我们在CSS中没有//注释? [英] Why don't we have a // comment in CSS?

查看:200
本文介绍了为什么我们在CSS中没有//注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:


$ b $

b


在CSS中,只有一种方法来创建注释: / *我是注释* / / p>

问题是它不可嵌套。



有人知道我们为什么没有替代注释语法如 //

解决方案

CSS像任何其他空格一样对待换行符,因此使用换行符终止的注释是没有意义的。这来自CSS1规范: http://www.w3.org/TR/REC-CSS1 p>

对于任何版本的CSS,CSS样式表都包含语句列表。有两种语句:规则和规则集。



当然,这在缩小的上下文中也有很大的意义,如下所示:为什么/ ** / comments在样式表中工作但//评论不会?


Possible Duplicate:
Why do /**/ comments work in stylesheets but // comments don't?

In CSS there is only one way to create comments: /* I'm a comment */

The problem is that it isn't nestable.

Does anyone know why we don't have an alternative comment syntax like //?

解决方案

I think the real answer is that CSS treats newlines like any other whitespace, so it wouldn't make sense to have comments that are terminated by a newline. This is from the CSS1 spec: http://www.w3.org/TR/REC-CSS1

A CSS style sheet, for any version of CSS, consists of a list of statements. There are two kinds of statements: at-rules and rulesets. There may be whitespace (spaces, tabs, newlines) around the statements.

Of course, this also makes a lot of sense in the context of minification, as mentioned here: Why do /**/ comments work in stylesheets but // comments don't?.

这篇关于为什么我们在CSS中没有//注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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