【问题标题】:How to achieve landscape and pixel ration media query with sass-breakpoint如何使用 sass-breakpoint 实现横向和像素比媒体查询
【发布时间】:2017-06-14 13:46:43
【问题描述】:

如何用 sass 断点实现这个媒体查询? ...

@media only screen 
  and (min-device-width: 375px) 
  and (max-device-width: 667px) 
  and (-webkit-min-device-pixel-ratio: 2)
  and (orientation: landscape)

我已经尝试过了,但它也会影响桌面版本...

$mobileLandscape: screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape);

@include breakpoint($mobileLandscape) {
}

【问题讨论】:

    标签: sass media-queries susy-compass susy breakpoint-sass


    【解决方案1】:

    这是如何使用断点 sass(breakpoint-sass bower 包)实现您想要的。 我已经在 chrome 中尝试过(并使用 web 开发工具模拟设备)并且它可以工作。

    // With third-party tool
    // Breakpoint https://github.com/at-import/breakpoint
    // You can find installation instructions here https://github.com/at-import/breakpoint/wiki/Installation
    $mobile-landscape-breakpoint: 'only screen' 375px 667px, (-webkit-min-device-pixel-ratio 2), (orientation landscape);
    
    body {
        @include breakpoint($mobile-landscape-breakpoint) {
            color: blue;
        }
    }
    

    如果断点看起来太复杂,您可以使用自己的代码来实现。 例如:

    // With Variable
    $mobileLandscape: "only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape)";
    
    @media #{$mobileLandscape} {
        body {
            color: red;
        }
    }
    
    // With Mixin
    @mixin mq($breakpoint){
        @if $breakpoint == "mobile-landscape"{
            @media only screen and (min-device-width: 375px) and (max-device-width: 667px) and (-webkit-min-device-pixel-ratio: 2) and (orientation: landscape){
                @content;
            }
        }
    }
    
    body{
        @include mq("mobile-landscape"){
            color: green;
        }
    }
    

    【讨论】:

    • 不,这不起作用,第一个使用断点的不是仅针对移动设备的景观,而是针对每个移动设备和平板电脑。第二种解决方案不使用 gulp-sass 进行编译。但是当使用媒体查询时它工作正常,我只想为这个媒体查询使用一个快捷方式,就是这样,所以我问如何使用断点来实现这个快捷方式。
    • 顺便说一句,mixin解决方案似乎可以工作,但我只是摸不着头脑,断点怎么办?一定有距离。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 2012-05-18
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    相关资源
    最近更新 更多