How to stretch background image with CSS?

Spread the love

Sometimes, we want to stretch background image with CSS.

In this article, we’ll look at how to stretch background image with CSS.

How to stretch background image with CSS?

To stretch background image with CSS, we set th background-size property.

For instance, we write

.style1 {
  background: url(images/bg.jpg) no-repeat center center fixed;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
}

to add background-size: cover; to maker the background image stretch to fit the container.

Conclusion

To stretch background image with CSS, we set th background-size property.

Leave a Reply

Your email address will not be published.