htmlimage-size

Change image size via parent 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>

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


Solution

  • 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%;
    }