scss Bootstrap断点SASS mixin

Posted

tags:

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

@mixin breakpoint($minWidth: 0, $maxWidth: 0, $minHeight: 0, $maxHeight: 0) {
  $type: type-of($minWidth);
	 
  @if $type == string {
  	$class: $minWidth; 

    @if $class == xs {
	    @media (max-width: 767px) { @content; }
	  }
	 
	  @else if $class == sm {
	    @media (min-width: 768px) { @content; }
	  }
	 
	  @else if $class == md {
	    @media (min-width: 992px) { @content; }
	  }
	 
	  @else if $class == lg {
	    @media (min-width: 1200px) { @content; }
	  }
	 
	  @else {
	    @warn "Breakpoint mixin supports: xs, sm, md, lg";
	  }
  }
  @else if $type == number {
	  $widthQuery: "all" !default;

	  // width
	  @if $minWidth != 0 and $maxWidth != 0 { 
	    $widthQuery: "(min-width: #{$minWidth}) and (max-width: #{$maxWidth})";
	  }
	  @else if $minWidth != 0 and $maxWidth == 0 { 
	    $widthQuery: "(min-width: #{$minWidth})"; 
	  }
	  @else if $minWidth == 0 and $maxWidth != 0 { 
	    $widthQuery: "(max-width: #{$maxWidth})"; 
	  }

	  // height
	  $heightQuery: 0;
	  @if $minHeight != 0 and $maxHeight != 0 { 
	    $heightQuery: "(min-height: #{$minHeight}) and (max-height: #{$maxHeight})";
	  }
	  @else if $minHeight != 0 and $maxHeight == 0 { 
	    $heightQuery: "(min-height: #{$minHeight})"; 
	  }
	  @else if $minHeight == 0 and $maxHeight != 0 { 
	    $heightQuery: "(max-height: #{$maxHeight})"; 
	  }

	  @if $minHeight != 0{
		  @media #{$widthQuery} and #{$heightQuery} { 
		    @content;
		  }
		}
	  @else if $maxHeight != 0{
		  @media #{$widthQuery} and #{$heightQuery} { 
		    @content;
		  }
	  }
	  @else if $minHeight != 0 and $maxHeight != 0{
		  @media #{$widthQuery} and #{$heightQuery} { 
		    @content;
		  }
	  }
	  @else {
		  @media #{$widthQuery} { 
		    @content;
		  }
		}

  }
}

// EXAMPLES:

//@include breakpoint($maxWidth: 700px, $minWidth: 500px, $maxHeight: 1500px, $minHeight: 600px){

// @include breakpoint($min: 400px, $max: 500px) {
// 	background-color: red;
// }

// aside.primary {
//   @include breakpoint(md) {
//     float: right;
//     width: 350px;
//   }
//   @include breakpoint(480px) {
//     display: none;
//   }
//   @include breakpoint($min: 640px, $max: 767px) {
//     text-align: center;
//     font-style: italic;
//   }
// }

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

scss 使用Sass地图的响应断点

scss 针对各种屏幕尺寸的SASS断点声明

scss 针对各种屏幕尺寸的SASS断点声明

scss 断点类工厂mixin for sass

scss 移动第一个Sass mixin用于常见断点

scss 添加xl步骤到bootstrap sass。应该是在bootstrap.scss之后。