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