2017-03-08 84 views
0

我目前正在努力使我的網站響應。由於我必須使用媒體查詢,我不知道哪種方法在行業中更常見,哪些方法會更好,更容易在SCSS中讀取/維護(CSS中的值僅用於演示)。在Sass/Scss中放置媒體查詢

例1:

.foo { 
    width : 10px; 
    .bar { 
    width : 20px; 
    } 
} 

@media screen and (max-width : 20px) { 
    .foo { 
    width : 20px; 
    .bar { 
     width : 30px; 
    } 
    } 
} 

例2:

.foo { 
    width : 10px; 
    @media screen and (max-width : 20px) { 
     width : 20px; 
    } 
    .bar { 
    width : 20px; 
    @media screen and (max-width : 20px) { 
     width : 30px; 
    } 
    } 
} 

例3:

.foo { 
    width : 10px; 
    @media screen and (max-width : 20px) { 
     width : 20px; 
     .bar { 
     width : 30px; 
     } 
    } 
    .bar { 
    width : 20px; 
    } 
} 

我知道,我可以使用混合類型和函數,而不是寫下來的全媒體查詢,我更感興趣的放置它們。

+2

我是唯一一個認爲這是基於意見的問題的人嗎? –

+0

@LaraBelle我想知道哪個更可能用於商業標準。 – August

+0

您可以全部使用它。大多數時候,你會使用第一個,但是會有時間需要使用第三個。 –

回答

1
A better option would be to create sass mixin for media query and use it 
e.g. 
bp = Break point 
@mixin bp-devices { 
    @media (min-width: 767px) { 
     @content; 
    } 
} 

and use it as 
footer { 
    padding: 25px 0 14px; 

    @include bp-devices { padding-bottom: 45px; } 
} 
+0

是的,我已經這樣做了,我想知道哪裏是放置斷點的最佳位置。但是,感謝您的意見。 – August