2017-01-29 74 views
5

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

回答

3

這是如何實現你想要的斷點青菜什麼(斷點,上海社會科學院亭子包)。 我試過它在鉻(並與網頁開發工具模擬設備),它的工作原理。

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

不,不工作,使用斷點不針對移動景觀的第一個唯一的,它的目標是每個手機和平板電腦。 第二種解決方案不使用gulp-sass進行編譯。 但是,當它使用媒體查詢時,它工作正常,我只想使用此媒體查詢的快捷方式,就是這樣,所以我問如何使用斷點來實現此快捷方式。 – Ruby

+0

mixin解決方案似乎工作的方式,但我只是抓我的頭,如何與斷點? 必須離開。 – Ruby