css - sass @include 以不同的方式工作

标签 css sass less compass-sass scss-lint

我在一个 Web 应用程序中发现了下面的代码,它正在生成如下所述的 css 无法理解这个包含的工作方式,据我所知,包含是一种函数调用,但我可以看到 { } 里面有一些代码。

sass 代码

   .sendfile-header-title {

      @include viewport(small) {
        text-align: center;
        display: block;
        border-bottom: solid 1px $secondary-gray;
        background: red;
      }

    }

css 生成代码

  @media only screen and (max-width: 735px) and (max-device-width:768px) {
        .sendfile-header-title {
            text-align:center;
            display: block;
            border-bottom: solid 1px #e0e0e0;
            background: red;
        }
    }

最佳答案

您使用@include 来调用混入。

让我用一个代码示例来解释这个过程:

//This way you define a mixin
@mixin viewport($breakpoint) {
    @if $breakpoint == small {
        @media only screen and (max-width: 735px) and (max-device-width:768px) {
            @content;
        }
    }
    @else ...
}



//This way you use a mixin
.sendfile-header-title {

    @include viewport(small) {
        //code ritten here will replace the @content inside the mixin
        //so the output in the css file will be a @media query applied to this element with the following code inside

        text-align: center;
        display: block;
        border-bottom: solid 1px $secondary-gray;
        background: red;
    }

}


//The css output will be:

//the @media query
@media only screen and (max-width: 735px) and (max-device-width:768px) { 
    //the element
    .sendfile-header-title {
        //the code
        text-align:center;
        display: block;
        border-bottom: solid 1px #e0e0e0;
        background: red;
    }
}

关于css - sass @include 以不同的方式工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38342834/

相关文章:

javascript - 父 css 文件处理上的 TinyMCE 和多个 CSS 选择器

html - 固定元素在移动设备上随顶部导航栏移动

css - SASS @import 根据屏幕尺寸导入多个文件

css - "undefined is not a function"咕噜声少

javascript - lessc 使用 Ruby 而不是 Javascript

html - 表格中的 Django 模板表单增加行高

css - 使用正则表达式将 CSS 分解成 block

html - 外部 div 背景在 Chrome 中可见 arround 内部 div

css - SCSS mixin 中的数学作为 for 循环的一部分

CSS3 过渡,悬停元素之前的目标元素