1
有条件地否定媒体查询
@mixin media($queries) {
@if length($queries) == 0 {
@content;
} @else {
$first-key: nth(map-keys($queries), 1);
@media ($first-key: map-get($queries, $first-key)) {
$queries: map-remove($queries, $first-key);
@include media($queries) {
@content;
}
}
}
}
我想用一个条件能够否定媒体查询,像这样:
@media not screen and ($first-key: map-get($queries, $first-key)) {
什么是动态添加它的正确语法?我尝试没有成功如下:
$invert: true;
$foo: if($invert, 'not screen and', null);
@media #{$foo} ($first-key: map-get($queries, $first-key)) {
错误:
Invalid CSS after "[email protected] #{$foo} ": expected "{", was "($first-key: ma..."
迭代查询看起来是这样的:
tablet: (
respond-to: (min-width: 421px, max-width: 992px)
)
使用时会导致下面的CSS:
@media (min-width: 421px) and (max-width: 992px) { }
谢谢,非常感谢 – Johan