【问题标题】:Comments in CSS make it wrongCSS 中的注释会出错
【发布时间】:2013-07-19 07:39:34
【问题描述】:

情况

我最近决定将 cmets 放入我的 CSS 文件中。一旦我这样做了,其中一个就停止了工作。

制作 cmets 的两种方法都会使我的整个 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,// 是一个无效的标记,使整个文件不可读。

【问题讨论】:

    标签: css comments


    【解决方案1】:

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

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

    rules关于浏览器在各种情况下应该做什么,但是我没有看到任何未知令牌(可能是我看起来不够好)。

    【讨论】:

    • 更新问题,请回答。
    【解决方案2】:

    使用 */ 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) */
    

    【讨论】:

      【解决方案3】:

      以这种方式尝试 cmets

      /* 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) */
      

      【讨论】:

        【解决方案4】:

        在 CSS 中评论的唯一方法是 /* this is a comnent */

        /*This is a comment*/
        p
        {
        text-align:center;
        /*This is another comment*/
        color:black;
        font-family:arial;
        }
        

        【讨论】:

          猜你喜欢
          • 2010-12-07
          • 1970-01-01
          • 2014-03-16
          • 2011-11-29
          • 2018-10-23
          • 1970-01-01
          • 2012-07-08
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多