百科狗-知识改变命运!
--

注释 - scss 语法

梵高1年前 (2023-11-21)阅读数 39#技术干货
文章标签注释

注释

Sass 注释的工作方式在 SCSS 和缩进语法之间有很大的不同。两种语法都支持两种类型的注释:使用/**/定义的注释,会被编译到 CSS 中,而使用//的注释,不会被编译进 css 文件中。

在SCSS中

SCSS中的注释与 JavaScript 等其他语言中的注释类似。单行注释,以开头//,一直到行尾。单行注释中的任何内容都不会编译进 CSS;就 Sass 而言,这类注释被视为不存在。它们也被称为静默注释,因为它们不产生任何 CSS。

多行注释,以/*开头,*/结尾。如果多行注释写在允许声明的地方,它会被编译为CSS注释。与静默注释相比,它们也被称为标准注释。编译为CSS的多行注释可能包含插值,将在编译注释之前对其进行计算。

默认情况下,多行注释会以压缩模式从编译后的 CSS 中去除。但是,如果注释以/*!开头,它将始终包含在CSS 输出中。

scsscss
// This comment won't be included in the CSS.

/* But this comment will, except in compressed mode. */

/* It can also contain interpolation:
 * 1 + 1 = #{1 + 1} */

/*! This comment will be included even in compressed mode. */

p /* Multi-line comments can be written anywhere
   * whitespace is allowed. */ .sans {
  font: Helvetica, // So can single-line commments.
        sans-serif;
}
/* But this comment will, except in compressed mode. */
/* It can also contain interpolation:
 * 1 + 1 = 2 */
/*! This comment will be included even in compressed mode. */
p .sans {
  font: Helvetica, sans-serif;
}


在 Sass 中

缩进语法中的注释的工作方式略有不同:它们是基于缩进的,就像语法的其余部分一样。与 SCSS 一样,使用//编写的静默注释,永远不会编辑进 CSS中,但与 SCSS 不同的是,//开头下方缩进的所有内容也会被注释掉。

以缩进开头的缩进语法中,注释/*以相同的方式工作,只是它们被编译为CSS。因为注释的扩展是基于缩进的,所以关闭*/是可选的。也像 SCSS 一样,/*注释可以包含插值,并且可以/*!开始,避免在压缩模式下被剥离。

默认,多行注释也可以在缩进语法的表达式中使用。在这种情况下,它们的语法与 SCSS 中的语法完全相同。

sasscss
// This comment won't be included in the CSS.
   This is also commented out.

/* But this comment will, except in compressed mode.

/* It can also contain interpolation:
   1 + 1 = #{1 + 1}

/*! This comment will be included even in compressed mode.

p .sans
  font: Helvetica, /* Inline comments must be closed. */ sans-serif 
/* But this comment will, except in compressed mode. */
/* It can also contain interpolation:
 * 1 + 1 = 2 */
/*! This comment will be included even in compressed mode. */
p .sans {
  font: Helvetica, sans-serif;
}

注释 - scss 语法


文档注释

使用 Sass 编写样式库时,您可以使用注释来记录您的库提供的 mixins、函数、变量和占位符选择器,以及库本身。这些是由 SassDoc 工具读取的注释,它使用它们来生成漂亮的文档。

文档注释是静默注释,在您正在记录的内容正上方用三个斜线(///)书写。SassDoc 将注释中的文本解析为 Markdown,并支持许多有用的注释来详细描述它。

scsscass
/// Computes an exponent.
///
/// @param {number} $base
///   The number to multiply by itself.
/// @param {integer (unitless)} $exponent
///   The number of `$base`s to multiply together.
/// @return {number} `$base` to the power of `$exponent`.
@function pow($base, $exponent) {
  $result: 1;
  @for $_ from 1 through $exponent {
    $result: $result * $base;
  }
  @return $result;
}
/// Computes an exponent.
///
/// @param {number} $base
///   The number to multiply by itself.
/// @param {integer (unitless)} $exponent
///   The number of `$base`s to multiply together.
/// @return {number} `$base` to the power of `$exponent`.
@function pow($base, $exponent)
  $result: 1
  @for $_ from 1 through $exponent
    $result: $result * $base

  @return $result

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)