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