Skip to content

Instantly share code, notes, and snippets.

@edk24
Last active June 21, 2024 15:34
Show Gist options
  • Save edk24/bee78788b1fdb1817964b97d2fab037b to your computer and use it in GitHub Desktop.
Save edk24/bee78788b1fdb1817964b97d2fab037b to your computer and use it in GitHub Desktop.
sass 响应式混入
$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;
}
}
*/
@edk24
Copy link
Author

edk24 commented Jun 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment