• scss-混合@mixin @include @function



    @mixin定义
    @mixin large-text {
    font: {
    family: Arial;
    size: 20px;
    weight: bold;
    }
    color: #ff0000;
    }
    1
    2
    3
    4
    5
    6
    7
    8
    父选择器

    @mixin clearfix {
    display: inline-block;
    &:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
    }
    * html & { height: 1px }
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    混合多个

    @mixin compound {
    @include highlighted-background;
    @include header-text;
    }
    @mixin highlighted-background { background-color: #fc0; }
    @mixin header-text { font-size: 20px; }
    1
    2
    3
    4
    5
    6
    @include 引入
    page-title {
    @include large-text;
    padding: 4px;
    margin-top: 10px;
    }
    1
    2
    3
    4
    5
    参数混合引入(可设置默认值)

    @mixin sexy-border($color, $ 1in) {
    border: {
    color: $color;
    $width;
    style: dashed;
    }
    }
    p { @include sexy-border(blue); }
    h1 { @include sexy-border(blue, 2in); }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    不确定参数个数,在参数后加 ...

    @mixin box-shadow($shadows...) {
    -moz-box-shadow: $shadows;
    -webkit-box-shadow: $shadows;
    box-shadow: $shadows;
    }
    .shadows {
    @include box-shadow(0px 4px 5px #666, 2px 6px 10px #999);
    }
    /*编译后*/
    .shadowed {
    -moz-box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
    -webkit-box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
    box-shadow: 0px 4px 5px #666, 2px 6px 10px #999;
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    定义数组数值,传入数组作为多个参数,传入参数加...

    @mixin colors($text, $background, $border) {
    color: $text;
    background-color: $background;
    border-color: $border;
    }
    $values: #ff0000, #00ff00, #0000ff;
    .primary {
    @include colors($values...);
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    标题@content在@mixin中插入内容
    将需要插入内容的位置用@content代替

    @mixin apply-to-ie6-only {
    * html {
    @content;
    }
    }
    @include apply-to-ie6-only {
    #logo {
    background-image: url(/logo.gif);
    }
    }
    /*编译后*/
    * html #logo {
    background-image: url(/logo.gif);
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    为便于书写,@mixin 可以用 = 表示,而 @include 可以用+表示

    =apply-to-ie6-only
    * html
    @content

    +apply-to-ie6-only
    #logo
    background-image: url(/logo.gif)
    1
    2
    3
    4
    5
    6
    7
    插入时的变量命名空间,使用时,插入的内容不能拿到mix内部的变量,而是同级以上的才可以取到

    $color: white;
    @mixin colors($color: blue) {
    background-color: $color;
    @content;
    border-color: $color;
    }
    .colors {
    @include colors { color: $color; }
    /*此处的$color 是取的全局的white*/
    }
    /*编译后*/
    .colors {
    background-color: blue;
    color: white;
    border-color: blue;
    }
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    @function
    函数声明用@function ,一个函数可以含有多条语句,需要调用 @return 输出结果。

    $grid- 40px;
    $gutter- 10px;
    @function grid-width($n) {
    @return $n * $grid-width + ($n - 1) * $gutter-width;
    }
    #sidebar { grid-width(5); }

    原文链接:https://blog.csdn.net/weixin_40054326/article/details/103061864

  • 相关阅读:
    shell脚本杀掉指定进程下所有子进程(包括子进程的子进程)
    XDebug调试
    PHP基础入门
    猴子补丁(Monkey Patching)
    编写python高质量python代码的59个有效方法
    ubuntu中不能使用终端的情况
    一些个人有用的网站
    Ubuntu将自带的python3升级
    [Vue warn]: You may have an infinite update loop in a component render function.
    OO第四单元总结&期末总结
  • 原文地址:https://www.cnblogs.com/onesea/p/15005552.html
Copyright © 2020-2023  润新知