如何用sass-breakpoint实现格局和像素定量媒体查询

时间:2017-01-29 06:44:56

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

如何使用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) {
}

1 个答案:

答案 0 :(得分:3)

这是如何用断点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;
    }
}