1

情况

我最近决定在我的 CSS 文件中添加注释。一旦我这样做了,其中一个就停止了工作。

两种发表评论的方式都会使我的整个 CSS 文件无法正常工作。我知道这是缺乏信息,我只是不知道它可能来自哪里。

万一这很重要,这就是我编写 CSS 的方式:

// Background
body            { background-color: #666666; }
#content            { background-color: #cccccc; }
#menu           { background-color: #cccccc; }
#menu-footer        { background-color: #33cccc; }
#menu-items a.active    { background-color: #33cccc; }
#menu-items a:hover     { background-color: #99cccc; }

// The white spaces are actually tabs (Alt+i on Emacs)

更新 1

我正在寻找调试这种情况的方法。我在 Google Chrome 的开发人员工具中看到我的 CSS 文件,但未应用属性。

foobar {
    // color: cyan;
}

这是否只是使 CSS 错误但仅在一行上?所以文件的其余部分继续被解析?


更新 2

我以前总是//评论我的 CSS,但我在这篇文章中使用了后来的符号。现在我改变主意并使用内联 CSS,//作为一个无效的标记会使整个文件不可读。

4

4 回答 4

3

css无法将双斜杠识别为注释。你必须使用那个 /* */

我可能错了,但由于双斜杠不是有效的 css 令牌,因此行为可能取决于浏览器。我希望浏览器简单地忽略后面的属性或语句//,但我从未检查/测试过。

有一些关于浏览器在各种情况下应该做什么的规则,但是我没有看到任何未知令牌(也许我看起来不够好)。

于 2013-07-19T21:43:56.763 回答
1

使用 */ Text */ ,而不是 // (// 是 javascript 中的注释)

/* Comment */

例如

/**** Background ****/
    body            { background-color: #666666; }
    #content            { background-color: #cccccc; }
    #menu           { background-color: #cccccc; }
    #menu-footer        { background-color: #33cccc; }
    #menu-items a.active    { background-color: #33cccc; }
    #menu-items a:hover     { background-color: #99cccc; }

/* The white spaces are actually tabs (Alt+i on Emacs) */
于 2013-07-19T22:17:51.533 回答
0

以这种方式尝试评论

/* Background */
body            { background-color: #666666; }
#content            { background-color: #cccccc; }
#menu           { background-color: #cccccc; }
#menu-footer        { background-color: #33cccc; }
#menu-items a.active    { background-color: #33cccc; }
#menu-items a:hover     { background-color: #99cccc; }

/* The white spaces are actually tabs (Alt+i on Emacs) */
于 2013-07-19T21:40:00.077 回答
0

在 CSS 中注释的唯一方法是/* this is a comnent */

/*This is a comment*/
p
{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}
于 2013-07-19T21:43:20.183 回答