0
當我有一個圖像的屬性width
和height
我的CSS重寫這些屬性,但如果我有寬度和高度的內聯樣式我的外部CSS不覆蓋內聯樣式。爲什麼?CSS覆蓋寬度和高度屬性。爲什麼?
實施例的代碼,而不加入CSS:
<img class="pic" src="http://cdn.cutestpaw.com/wp-content/uploads/2012/07/l-Wittle-puppy-yawning.jpg" width="100" height="100" />
實施例的代碼添加了CSS:
.pic {
width: auto;
height: auto;
}
<img class="pic" src="http://cdn.cutestpaw.com/wp-content/uploads/2012/07/l-Wittle-puppy-yawning.jpg" width="100" height="100" />
實施例的代碼,其中i n線風格:
.pic {
width: auto;
height: auto;
}
<img class="pic" src="http://cdn.cutestpaw.com/wp-content/uploads/2012/07/l-Wittle-puppy-yawning.jpg" style="width: 100px; height: 100px" />
我明白這一點。我的問題更多地針對外部CSS重寫內聯屬性的原因。 – Anthony
這很有趣。我希望這種行爲,否則你永遠無法調整圖像的外部大小的CSS媒體查詢等。有一個高度和寬度attr不會保留在瀏覽器中的空間,所以我想你可以讓你的蛋糕也吃了。 –
我的假設是它將屬性寫爲非內聯CSS,然後外部CSS出現並覆蓋CSS屬性選擇器。 – Anthony