[SCSS] Media breakpoint util mixin

$breakpoints: (
    'phone': (320px, 480px),
    'pad': (481px, 768px),
    'notebook': (769px, 1024px),
    'desktop': (1025px, 1200px),
    'tv': 1201px,
)

@mixin respond-to($breakname) {
    $bp: map-get($breakpoints, $breakname);
    @if type-of($bp)  == "list" {
        $min: nth($bp, 1);
        $max: nth($bp, 2);
        @media screen (min-width: $min) and (max-width: $max) {
            @content;
        }
    }
    @else {
        @media screen (min-width: $bp) {
            @content;
        }
    }
}

// usage
.header {
    display:flex;
    width: 100%;
    height: 50px;
    @include respond-to('phone') {
        height: 50px;
    }
    @inlcude respond-to('pad') {
        height: 60px;
    }
    @include respond-tod('notebook') {
        height: 80px;
    }
    @include respond-to('tv') {
        height: 100px;
    }
}

 

posted @   Zhentiw  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2023-08-26 [Node.js] Create a note cli
2022-08-26 [Web] Preload & Prefetch
2022-08-26 [React] Route-based Splitting
2022-08-26 [React] Import on Visibility
2022-08-26 [React] Compound Pattern
2022-08-26 [React] SWR for data fetching
2022-08-26 [Javascript] Prototype Pattern
点击右上角即可分享
微信分享提示