我有一个基于 Twitter Bootstrap 响应式媒体查询的 Sass mixin 用于我的媒体查询:
@mixin respond-to($media) {
@if $media == handhelds {
/* Landscape phones and down */
@media (max-width: 480px) { @content; }
}
@else if $media == small {
/* Landscape phone to portrait tablet */
@media (max-width: 767px) {@content; }
}
@else if $media == medium {
/* Portrait tablet to landscape and desktop */
@media (min-width: 768px) and (max-width: 979px) { @content; }
}
@else if $media == large {
/* Large desktop */
@media (min-width: 1200px) { @content; }
}
@else {
@media only screen and (max-width: #{$media}px) { @content; }
}
}
我在我的 SCSS 文件中这样称呼它们:
.link {
color:blue;
@include respond-to(medium) {
color: red;
}
}
但是,有时我想用相同的样式设置多个查询的样式。现在我正在这样做:
.link {
color:blue; /* this is fine for handheld and small sizes*/
/*now I want to change the styles that are cascading to medium and large*/
@include respond-to(medium) {
color: red;
}
@include respond-to(large) {
color: red;
}
}
但我在重复代码,所以我想知道是否有更简洁的方法来编写它,以便我可以针对多个查询。像这样的东西,所以我不需要重复我的代码(我知道这不起作用):
@include respond-to(medium, large) {
color: red;
}
有关处理此问题的最佳方法的任何建议?