2016-11-29 83 views
1

我的媒體查詢存在問題,因爲它並不是互相覆蓋。第一次迭代(max-width: 960px)工作正常,但第二個(max-width: 380px)不起作用,我不知道爲什麼。非常感謝幫助,謝謝。媒體查詢不互相覆蓋

.fb { 
 
    width: 50px; 
 
    margin-left: 20px; 
 
    margin-right: 20px; 
 
} 
 

 
@media only screen and (max-width: 960px) { 
 

 
/* this works */ 
 

 
.fb { 
 
    position: relative; 
 
    width: 40px!important; 
 
    margin-left: 15px!important; 
 
    margin-right: 15px!important;     
 
      } 
 
} 
 

 

 
@media only screen and (max-width: 380px) { 
 

 
/* this does not work */ 
 
.fb { 
 

 
    width: 30px!important; 
 
    margin-left: 10px!important; 
 
    margin-right: 10px!important;    
 
      } 
 
}
<div class="social_container"> 
 
<a href="https://www.facebook.com/" target="_blank"><img class="fb" src= "http://placekitten.com/200/300" alt=""></a> 
 
</div>

+0

爲什麼'!important'?另外,您最後一條規則中有一個錯字:「margin-rigth」。什麼「不起作用」? – connexo

+0

你可以發佈一個有效的小代碼片段與示例圖像嗎?我們無法調試我們無法看到的內容。 –

+0

好的,只需一秒鐘。 –

回答

2

你拼寫錯誤保證金分辯請改爲保證金右並刪除!重要

.fb { 
 
    width: 50px; 
 
    margin-left: 20px; 
 
    margin-right: 20px; 
 
} 
 
@media only screen and (max-width: 960px) { 
 
    .fb { 
 
    position: relative; 
 
    width: 40px; 
 
    margin-left: 15px; 
 
    margin-right: 15px; 
 
    } 
 
} 
 
@media only screen and (max-width: 380px) { 
 
    .fb { 
 
    width: 30px; 
 
    margin-left: 10px; 
 
    margin-right: 10px; 
 
    } 
 
}
<div class="social_container"> 
 
    <a href="https://www.facebook.com/" target="_blank"> 
 
    <img class="fb" src="https://i.stack.imgur.com/UzPkq.jpg" alt=""> 
 
    </a> 
 
</div>

+0

您應該刪除代碼中的註釋。 – connexo

+0

好吧,我完成了... –

+0

現在,在代碼編輯器中按下「Tidy」按鈕,我將upvote。此外,我建議你使用像placehold.it或placekitten.com圖像佔位符服務。 – connexo

-1

看到fiddle

.social_container a { 
 
    color: red; 
 
} 
 

 
@media only screen and (max-width: 960px) { 
 

 

 
.social_container a{ 
 
    color: green; 
 
} 
 

 
} 
 
@media only screen and (max-width: 380px) { 
 

 
.social_container a{ 
 

 
    color: pink; 
 
      } 
 
}
<div class="social_container"> 
 
<a href="https://www.facebook.com/" target="_blank">fb</a> 
 
</div>

+0

OP的選擇器是完全有效的,這裏沒有問題。你的答案如何有用? – connexo