scss Bootstrap mixins

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了scss Bootstrap mixins相关的知识,希望对你有一定的参考价值。

@mixin respond($minWidth: 0, $maxWidth: 0) {
    @if $minWidth and $maxWidth
    {
        @media screen and (min-width: $minWidth) and (max-width: $maxWidth) { @content; }
    }
    @else if $minWidth
    {
        @media screen and (min-width: $minWidth) { @content; }
    }
    @else if $maxWidth
    {
        @media screen and (max-width: $maxWidth) { @content; }
    }
    @else
    {
        @warn "error - undefined params";
    }
}


@mixin breakpoint($class) 
{

    @if $class == xs
    {
        @media (max-width: 480px) { @content; } 
    }

    @elseif $class == is 
    {
        @media (max-width: 767px) { @content; }
    }

    @else if $class == sm 
    {
        @media (max-width: 991px){ @content; }
    }

    @else if $class == md 
    {
        @media (max-width: 1199px) { @content; }
    }

    @else if $class == lg 
    {
        @media (min-width: 1200px) { @content; }
    }

    @else 
    {
        @warn "Breakpoint mixin supports: is, xs, sm, md, lg";
    }
}


#test
{
    @include breakpoint(lg)
    {
        background: red;
    }

    @include breakpoint(md)
    {
        background: green;
    }    

    @include breakpoint(sm)
    {
        background: purple;
    }

    @include breakpoint(xs)
    {
        background: blue;
    }

    @include breakpoint(is)
    {
        background: gold;
    }
}

以上是关于scss Bootstrap mixins的主要内容,如果未能解决你的问题,请参考以下文章

scss Bootstrap 4 Mixins实用程序

scss Bootstrap mixins

scss 带有mixins的Bootstrap断点。

scss 带有mixins的Bootstrap断点。

scss Bootstrap Sass Mixin Cheatsheet

scss Bootstrap Sass Mixin Cheatsheet