通过父DIV更改图像大小 [英] Change image size via parent DIV

查看:92
本文介绍了通过父DIV更改图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这样做,但没有改变尺寸:

I tried to do so but it didn't change the size:

<div style="height:42px;width:42px">
   <img src="http://someimage.jpg">
</div>

什么会重新调整大小(我无法编辑/触摸img元素本身)。

What will re-size it (I can't edit/touch the img element itself).

预先感谢。

推荐答案

我不确定您的意思是我无法访问图片但是如果您有权访问父div,您可以执行以下操作:

I'm not sure about what you mean by "I have no access to image" But if you have access to parent div you can do the following:

冷杉给您的div赋予id或class:

Firs give id or class to your div:

<div class="parent">
   <img src="http://someimage.jpg">
</div>

比添加到您的css:

.parent {
   width: 42px; /* I took the width from your post and placed it in css */
   height: 42px;
}

/* This will style any <img> element in .parent div */
.parent img {
   height: 100%;
   width: 100%;
}

这篇关于通过父DIV更改图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆