我有一個基於Twitter的引導的響應媒體查詢我的媒體查詢薩斯混入:處理自定義媒體查詢在薩斯與Twitter的引導
@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;
}
在處理這種最好的方式有什麼建議?
嗯,它仍然是級聯風格,所以適合中型適合大型(因爲您正在使用最小寬度媒體查詢)否? –
不,所以我應該更具體(我會編輯問題)。假設我的默認樣式(適用於手持設備和移動設備)可以是顏色:藍色;但後來我想要大中的顏色:紅色。它會級聯,但我想覆蓋大中型。那有意義嗎? – Keith