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