Change image size via parent div

funerr picture funerr · Mar 4, 2012 · Viewed 126.5k times · Source

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

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

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

Thanks in advance.

Answer

Ilja picture Ilja · Mar 4, 2012

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:

Firs give id or class to your div:

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

Than add this to your 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%;
}