2016-06-21 76 views
1

我正試圖隱藏僅在移動視圖中使用的背景圖像。隱藏某些媒體查詢值中的背景圖像

html{ 
background: #fff url('//www.xxxxxxxxx.xxx/gray.jpg') center top no-repeat; 
background-attachment: initial; 
background-size: contain; 
background-position-y: 0; 
} 

但是,當我這樣做:

@media (max-width: 425px){ 
background: transparent !important; 
} 

背景不能識別的查詢規則設置HTML。我怎樣才能做到這一點?我究竟做錯了什麼?

+0

Alberto,我已經更新了標題以更具體到您的問題。如果我錯過了某些東西,請隨時回滾。 –

回答

3

您還必須在媒體查詢中使用CSS選擇器。在這種情況下,請添加html { ... }。試試這個:

@media (max-width: 425px){ 
    html { 
     background: transparent !important; 
    } 
}