【发布时间】:2019-02-08 23:03:13
【问题描述】:
我有一个用于媒体查询的 SASS mixin,效果很好,尤其是在嵌套时,但问题是我似乎无法弄清楚如何编写我的 mixin,以便我可以组合不同的媒体查询。有没有一种方法可以让我的 mixin 保持简单但允许多个组合查询?
例如:
@include media(tablet-p) and media(phone) {
width: 100%;
}
下面是我当前的 mixin,包括我当前的使用方式。
@mixin media($size) {
@if $size == laptop {
@media screen and (min-width:1201px) and (max-width:1440px) {
@content;
}
} @else if $size == tablet-l {
@media screen and (min-width:1024px) and (max-width:1200px) {
@content;
}
} @else if $size == tablet-p {
@media screen and (min-width:768px) and (max-width:1023px) {
@content;
}
} @else if $size == phone {
@media screen and (max-width: 767px) {
@content;
}
}
}
@include media(phone) {
width: 100%;
}
【问题讨论】: