Last active
June 21, 2024 15:34
-
-
Save edk24/bee78788b1fdb1817964b97d2fab037b to your computer and use it in GitHub Desktop.
sass 响应式混入
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$breakpoints: ( | |
'phone': (320px, 480px), | |
'pad': (481px, 768px), | |
'notebook': (769px, 1024px), | |
'desktop': (1025px, 1200px), | |
'tv': 1201px | |
); | |
@mixin respondTo($media) { | |
$dp: map-get($breakpoints, $media); | |
@if type-of($dp) == 'list' { | |
$min: nth($dp, 1); | |
$max: nth($dp, 2); | |
@media (min-width: $min) and (max-width: $max) { | |
@content; | |
} | |
} | |
@else { | |
@media (min-width: $dp) { | |
@content; | |
} | |
} | |
} | |
/* 使用方法 Usage */ | |
/* | |
.header { | |
@include respondTo('phone') { | |
// CSS here | |
background-color: red; | |
} | |
@include respondTo('pad') { | |
// CSS here | |
background-color: blue; | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
实现来源:https://www.bilibili.com/video/BV1TM4m167VN/