css - 仅将图像调整到一定大小

标签 css wordpress

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

img {
    width:200px !important;
}

这工作正常,因为只设置了宽度大小,高度调整为原始图像的正确比例,并且 !important 覆盖导入帖子中设置的图像大小。

然而,在导入的帖子(例如来自 feedburner 等)中也有我不想调整大小的社交媒体分享图片,例如

enter image description here

我可以为 css 图像大小添加过滤器以仅应用于特定大小(例如超过 100 像素宽)的图像吗?

注意我试着在标题中添加这个

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

我要调整大小的图片的 div 在哪里

<DIV class="myDivClass">

但这没有用。

最佳答案

您必须使用 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;
}

关于css - 仅将图像调整到一定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44402366/

相关文章:

javascript - 如何编辑 WooCommerce 搜索字段占位符?

mysql - 如何检查黑客是否修改或更改了表或向数据库添加了列

css - 如何滚动tbody?

css - 使 css 文件仅匹配特定 id 的工具

html - 如何在 CSS 中排列列表元素符号?

php - WooCommerce 管理员订单编辑保存帖子

html - 为什么 "Inline-block"在此 CSS 中不能正常工作?

html - 为什么.class :last-of-type not work as I expect?

php - WordPress 数据库丢失

mysql - 通过mysql删除许多Wordpress用户