仅调整特定大小的图像

时间:2017-06-07 02:08:32

标签: css wordpress

我正在使用Wordpress插件使用RSS源从其他网站导入博客帖子。导入的帖子包含我使用css设置为统一大小的图像

img {
    width:200px !important;
}

这样就行了,因为只设置宽度尺寸,高度调整为原始图像的正确比例,而!important会覆盖导入帖子中设置的图像尺寸。

然而,在进口的帖子中也有社交媒体共享图像(例如来自feedburner等),我不想调整大小,例如。

enter image description here

我可以在css图像尺寸上添加滤镜,仅适用于特定尺寸的图像(例如宽度超过100像素)吗?

N.B。我尝试在标题中添加它

<script type = "text/javascript" language = "javascript">
 $(document).ready(function() {
	$("myDivClass").css(img{ width:200px !important;});
 });
</script>

带有我要调整大小的图像的div是

<DIV class="myDivClass">

但这不起作用。

2 个答案:

答案 0 :(得分:0)

您必须使用div类选择图像。

例如,您的代码是:

<div class="parentofall">
    <div class="firstparent">
        <img src="imageurl">
    </div>
    <div class="secondparent">
        <img src="imageurl">
    </div>
    <div class="thirdparent">
        <img src="imageurl">
    </div>
</div>

你的CSS应该喜欢这个:

.parentofall .firstparent img {
    width: 100px;
    height: 100px;
}

要选择所选图像,或者只需选择firstparent而不使用parentofall。

转到所选图像的另一种方法是:

.parentofall > firstparent img {
width: 100px;
height: 100px;
}

答案 1 :(得分:0)

最后使用它

    <script>
	
    $( document ).ready(function() {
		$(".MyDivClass img").width(200); 
    });
	
    </script>

相关问题