2

我正在使用 Mac 10.7.2、Ruby 1.9.3 和 SASS 3.2.1。我正在尝试在多级 CSS 之间获取多行注释和注释。我知道我们可以在 SASS 中实现多行注释,如下所示:

SASS

/*
 Multiline
 comments
 goes here

CSS

/* Multiline
 * comments
 * goes here */

但是我在我的样式表中使用了不同的注释来突出/识别我的 CSS 中的多个级别和不同的东西,其中两个如下:

我的样式表以下面的评论开头:

/***************************************************************

Theme Name: Theme name goes here
Theme URI: Theme URL goes here
Description: Discription related to theme will goes here
Version: 1.1
Author: Author name goes here
Author URI: Authour url goes here

***************************************************************/

我的应用程序索引评论如下:

/*
---------------------------------------
---------------------------------------
--- Table of Contents:              ---
---                                 ---
--- 1. HEADER                       ---
--- -1.1 Navigation Bar             ---
---                                 ---
---                                 ---
--- 2. MAIN SECTION                 ---
--- -2.1 Home page                  ---
--- --2.1.1 Sections                ---
--- ---2.1.1.1 sub section          ---
---                                 ---
---                                 ---
--- 3. FOOTER                       ---
---------------------------------------
---------------------------------------
*/

我可以找到更接近它的评论,但无法将其完全作为编译后的 CSS 评论

SASS

/*
  ---------------------------------------
  ---------------------------------------
  --- Table of Contents:              ---
  ---                                 ---
  --- 1. DEFAULT ELEMENTS             ---
  --- 2. LINKS                        ---
  --- 3. TABLE                        ---
  --- 4. FORM                         ---
  --- 5. GLOBAL CLASSES               ---
  ---------------------------------------
  ---------------------------------------

CSS

/*  ---------------------------------------
 *  ---------------------------------------
 *  --- Table of Contents:              ---
 *  ---                                 ---
 *  --- 1. DEFAULT ELEMENTS             ---
 *  --- 2. LINKS                        ---
 *  --- 3. TABLE                        ---
 *  --- 4. FORM                         ---
 *  --- 5. GLOBAL CLASSES               ---
 *  ---------------------------------------
 *  --------------------------------------- */

还有一些时候我们需要多层次的评论

.firstLavel
  background: #f00
  /* comeent goes here before second level */
  .secondLavel
    font-size:  20
    color:  #ddd
  /* comeent goes here before third level
  .secondLavel
    font-size:  70
    color:  #ded

但我得到了结果:

  background: red;
  /* comeent goes here before second level */
  /* comeent goes here before third level */ }
  .firstLavel .secondLavel {
    font-size: 20;
    color: #dddddd; }
  .firstLavel .secondLavel {
    font-size: 70;
    color: #ddeedd; }

它应该是:

.firstLavel {
  background: red; }

  /* comment goes here before second level */
  .firstLavel .secondLavel {
    font-size: 20;
    color: #dddddd; }

  /* comment goes here before third level */ 
  .firstLavel .secondLavel {
    font-size: 70;
    color: #ddeedd; }
4

1 回答 1

1

Sass 使用一种算法进行编译,该算法递归地渲染 CSS 树的所有子节点,从端点(没有更深层次的端点)开始。由于这种算法,当它不是端点时,不可能在子节点之前设置评论:评论永远不会有更深的层次。设置评论的唯一方法是将评论设置为节点的子节点。

为了澄清,考虑这棵树:

root
  child1 
    child1.1
      /* comment on 1.1*/
      child1.1.1
    child1.2
  child2
  /* comment on 2 */
  child3
    /* comment on 3*/
    child3.1
  child4

渲染它将首先导致没有子项的条目,然后是更深的条目。CSS 的顺序为:

root
  child2
  /* comment on 2 */
  child4
  child1
    child1.2
    child1.1
      /* comment on 1.1 */
      child1.1.1
  child3
    /* comment on 3 */
    child3.1

使用的算法是带有队列的BSF,该队列将端点放在首位

于 2012-12-03T14:33:05.420 回答