Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve landscape and pixel ration media query with sass-breakpoint

How to achieve this media query with sass breakpoint? ...

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

I've tried this, but it affects the desktop version as well ...

$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) {
}
like image 781
Ruby Avatar asked Oct 18 '22 18:10

Ruby


1 Answers

This is how to achieve what you want with breakpoint sass (breakpoint-sass bower package). I have tried it in chrome (and simulate device with web developper tools) and it works.

// 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;
    }
}

If breakpoint seems too complicated, You can achieve this with your own code. For example :

// 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;
    }
}
like image 97
rdhainaut Avatar answered Oct 21 '22 06:10

rdhainaut