Sass教程

Sass: 定义Mixin

Sass: 定义Mixin

@mixin指令定义了mixin。它用于在mixin名称之后可选地包括变量和参数。
让我们以一个示例来演示如何定义mixin。在这里,我们获取一个名为" simple.html"的HTML文件,其中包含以下代码。
<html>
<head>
   <title>Define a mixin example</title>
   <link rel="stylesheet" type="text/css" href="simple.css"/>
</head>
<body>
<div class="cont">
   <h1>Define a mixin directive.</h1>
   <h3>It is used to include optionally the variables and arguments after the name of the mixin.</h3>
</div>
</body>
</html>
采用一个SCSS文件名" simple.scss",具有以下代码:
@mixin style {
.cont{
 color: #FF0000 ;
    }
}
@include style;
打开命令提示符,然后运行 watch 命令告诉SASS监视文件,并在更改SASS文件时更新CSS。
sass--watch simple.scss: simple.css
Sass定义mixin1
执行上述命令后命令,它将使用以下代码自动创建一个名为" simple.css"的CSS文件。
. cont {
  color: #FF0000 ;}
您可以看到自动创建的CSS文件。
Sass定义mixin2
输出:
应用CSS后查看输出。
Sass定义mixin3
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4