[英]how to resize images inside a div inside another div with css?
I want to only resize images that are in a div with a specific class, inside an other div with an other specific class. 我只想调整具有特定类的div中具有其他特定类的div中的图像的大小。 but the images which are only inside the div which is inside the other div should not be resized.
但仅应调整位于另一个div内的div内的图像的大小。
This works if I want to resize images inside a classed div: 如果我要在已分类的div中调整图像大小,则此方法有效:
div.classname>img { width:something; }
but this doesn't work: 但这不起作用:
div.classname2 > div.classname > img { width:something; }
Markup 标记
<div class="classname2">
<div class="classname">
<img>
</div>
</div>
But I can't refer to it with the inside class name. 但是我不能用内部类名来引用它。
So, to make it really clear, i need to resize these images: 因此,要弄清楚,我需要调整这些图像的大小:
<div class="classname2">
<div class="classname">
<img>
</div>
</div>
But not these: 但不是这些:
<div class="classname">
<img>
</div>
I think this should work 我认为这应该工作
CSS 的CSS
.classname2 .classname img { width: 200px; }
Having: 具有:
<div class="parentDiv">
<img class="img1">
<div class="childDiv">
<img class="img2">
</div>
</div>
do it like this: 像这样做:
.parentDiv > img { width: 100px }
will just effect <img>
s having class="img1"
not those having class="img2"
只会影响具有
class="img1"
<img>
而不影响具有class="img2"
那些
Edit the only the single image you want without changing the rest, by going to that specific tag and putting the following style attributes. 通过转到该特定标签并放置以下样式属性,可以仅编辑所需的单个图像,而无需更改其余图像。
<img class = "example" style = "width: 50px !important;">
UPDATE 更新
Give this a try, add "!important" to the inside class to override the parent. 尝试一下,在内部类中添加“!important”以覆盖父类。
div.classname2 > div.classname > img { width:something !important; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.