Sass之注释学习教程

本文介绍了SASS中的注释用法,包括多行注释和单行注释的区别及如何在SCSS文件中使用它们。多行注释会被保留在CSS输出中,而单行注释则不会。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在本章中,让我们学习SASS 的注释。注释是放置在源代码中不可执行的语句。注释使源代码更易于理解。SASS支持两种类型的注释。

 

 

 

多行注释 - 这些使用 /**/ 写入。多行注释都保留在CSS输出。

 

单行注释 - 这些是使用//跟着注释。单行注释不会保留在CSS输出。

 

实例

下面的例子演示了SCSS 文件中使用注释:

<html>

<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>SASS注释 - www.yiibai.com</title>

   <link rel="stylesheet" type="text/css" href="style.css"/>

</head>

<body>

  <h1>Welcome to YiiBai</h1>

  <a href="http://www.yiibai.com/">Yiibai Yiibai</a>

</body>

</html>

接下来创建一个文件:style.scss.

style.scss

/* This comment is

 * more than one line long

 * since it uses the CSS comment syntax,

 * it will appear in the CSS output. */

body { color: black; }

 

// These comments are in single line

// They will not appear in the CSS output,

// since they use the single-line comment syntax.

a { color: blue; }

可以告诉SASS监视文件,并随时使用下面的命令更新SASS文件修改CSS

sass --watch C:\Ruby22-x64\style.scss:style.css

接着执行上面的命令,它会自动创建style.css文件,如下面的代码:

style.css

/* This comment is

 * more than one line long

 * since it uses the CSS comment syntax,

 * it will appear in the CSS output. */

body {

  color: black; }

 

a {

  color: blue; }

输出

让我们来执行以下步骤,看看上面的代码输出:

 

保存上面的html代码在 sass_comments.html 文件。

 

 

在浏览器中打开该HTML文件,得到输出结果如下。

 

 

 

 

 

原文来自:易百

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值