5

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

1 回答 1

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;
    }
}
于 2017-02-01T08:35:52.430 回答