Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image width the same as parent element?

Tags:

css

I have an image which I need to a max width as its parent element.

With this code the image is shown with a width of 600px. I need the image to have a width equal to 400px, even though the natural width of the image is 600px.

How can I do this?

<div style="width: 400px">
   <table>
    <tr><td>
      <img widht="600" ..../>
   </td></tr>
  </table>
</div>

I have this css:

table, img
{max-width:100%}
like image 303
chefnelone Avatar asked Jun 25 '26 14:06

chefnelone


1 Answers

 img{  width: 100%; }

will sort you out. This will 'expand' the image width the the size of the containing element.

like image 59
Pat Dobson Avatar answered Jun 28 '26 06:06

Pat Dobson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!