我想知道当我的屏幕分辨率低于 980 像素时,是否有某种方法可以删除图像的宽度和高度?通过 jquery 什么的?
像这样的图像:
<img width="477" height="299" src="/uploads/2012/01/415.jpg" class="attachment-portfolio2 wp-post-image"/>
谢谢
您可以使用以下 CSS:
/* for all screens in general */
.wp-post-image {
width: 477px;
height: 299px;
}
/* specifically for screens smaller than (or equal to) 980px */
/* make sure this comes *after* the general rule */
@media (max-width: 980px) {
.wp-post-image {
width: auto;
height: auto;
}
}
您可以使用 jQueryremoveAttr()
方法:
var images;
$(function() {
images = $('img.wp-post-image');
removeSize();
});
$(window).resize(removeResize);
function removeSize()
{
if($(window).width() < 980 && images.length > 0)
{
images.removeAttr('width').removeAttr('height');
}
}