Как добиться медийного запроса с альбомной ориентацией и пиксельным соотношением с помощью sass-breakpoint

Как добиться этого медиа-запроса с помощью 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 ответ

Это то, как добиться того, чего вы хотите, с помощью sass точки останова (пакет bower breakpoint-sass). Я попробовал его в Chrome (и имитировать устройство с помощью инструментов веб-разработчик), и он работает.

// 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;
    }
}
Другие вопросы по тегам