我已经创建了一个 chrome 扩展。我有个疑问。我希望任何网站的每张图片都具有最小宽度的样式 css。
我不需要影响所有图像,只影响具有最小宽度的图像。
最佳答案
默认情况下所有元素都有 min-width="0px"
所以简单地检查图像是否没有 min-width-"0px"
做这个
例如
$("img").each(function(e) {
if ($(this).css("min-width") != "0px") {
$(this).addClass("foo")
} else {
$(this).removeClass("foo") //no need this line but just added as a fallback
}
});
.test {
min-width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150" style="min-width:100%">
<img src="http://placehold.it/350x150" class="test">
在这种情况下,我在那些具有最小宽度 css 的图像上添加了 foo 类,你可以做任何你想做的事。
我不知道它是否是一个合适的解决方案,但它会帮助你做任何你想做的事。
谢谢
关于jquery - 影响所有宽度最小宽度的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36499805/