Home html Analogue background-size: cover for img

Analogue background-size: cover for img

Author

Date

Category

Is it possible to do the same image positioning in the img tag as with background-size: cover ?

I saw solutions using object-fit , also looked at other options, but none of them work. Can I do without object-fit ?


Answer 1, authority 100%

The object-fit property works: most likely you misapplied or looked at it in IE. Below is an example of the correct use of the property:

# bg {
  height: 100vh;
  width: 100%;
  position: relative;
}
#bg img {
  object-fit: cover;
  height: 100%;
  width: 100%;
} 
& lt; html & gt;
& lt; body & gt;
  & lt; div id = "bg" & gt;
    & lt; img src = "https://1000.tech/img/bg0.jpg" & gt;
  & lt; / div & gt;
& lt; / body & gt;
& lt; / html & gt; 

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions