代码之家  ›  专栏  ›  技术社区  ›  DarkFenix

为什么@custom media不在sass中应用相应的样式

  •  0
  • DarkFenix  · 技术社区  · 7 年前

    我正在尝试用CSS网格和新规范的响应部分制作基本布局 CSS level 4 ,但在编译sass的内容时,它对我不起作用,我是否有什么地方失败了?我是否遗漏了任何细节?

    自定义媒体。scss公司

    *{ margin: 0 ; padding: 0}
    
    @custom-media --phone  ( 320px < width < 480px); 
    @custom-media --tablets (481px < width  < 767px);
    @custom-media --ipad-landscape  (768px < width < 1024px) and (orientation: landscape);
    @custom-media --ipad-normal  (768px < width < 1024px);
    @custom-media --desktop  (1025px < width  < 1280px);
    @custom-media --large  (width > 1281px);
    

    应用程序。scss公司

    @import 'custom-media';
    
    /**
     *
     * Login Page
     *
     */
     .container{
        width: 100vw;
        height: 100vh;
        display: grid;
        grid-template-columns: 60% 1fr;
        grid-row: 1fr;
    
        .presentation{
            background:#CB3BBF;
        }
    
        .loginsection{
    
        }
    
        @media  (--desktop) {
            .container {
                grid-template-columns: 1fr; 
            }
    
            .presentation{
                background:blue;
            }
        }
    }
    

    我尝试将宽度设置为1025px和1280 px之间的蓝色背景色,但它不起作用 铬版本n 64.0.3282.186

    2 回复  |  直到 7 年前
        1
  •  1
  •   Jithin Raj P R    7 年前

    您可以使用

    @mixin responsive($size) { @if $size == large { /* 1920px / @media (max-width: 120em) { @content; } } @if $size == small { / 1199px */ @media (max-width: 74.938em) { @content; } } } @include responsive(large){ font-size: 42px; } @include responsive(small){ font-size: 22px; }
    

    这将起作用。

        2
  •  0
  •   code monkey    3 年前

    截至目前(2021 12月),虽然在规范中,@自定义媒体尚未在任何地方实现。也不 caniuse 也没有 MDN 了解@自定义媒体。