Home > Software design >  styling <div> and <img> using URL is not working even if same styled has been applied?
styling <div> and <img> using URL is not working even if same styled has been applied?

Time:09-12

I have the following example where I use same styling of an image, and on a div.

The point is the property on a div makes the image looks way better, yet on the image makes the image distorted. what is the deal here? I am using the same styling for both yet somehow, it is not being applied as it should. Code sand box example

CodePudding user response:

We see that the image is being squished to fit the container. For fix this you must set property "object-fit: cover;".

CodePudding user response:

When style is set directly on <img>:

  1. You set fixed dimensions that does not match with actual image and it disproportion your image
  2. Any background* property does not work, as image is not as background

When style is set directly on <div>:

  1. You set fixed dimensions for container, not image.
  2. Background image then can extend beyond container and is not in dispropotion
  • Related