Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (20.3k points)

Is there a way to get a background in CSS to stretch or scale to fill its container?

1 Answer

0 votes
by (40.7k points)

For modern browsers like Safari 3 (or later), Chrome, Opera 10+, Firefox 3.6+, and Internet Explorer 9, you can use background-size like this:

body {

    background-image: url(bg.jpg);

    background-size: cover;

}

Here, cover means stretching the image either vertically or horizontally so it never tiles/repeats.

For lower versions of Internet Explorer, try using the below CSS code:

filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.myBackground.jpg', sizingMethod='scale');

-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='myBackground.jpg', sizingMethod='scale')";

Related questions

0 votes
1 answer
asked Aug 26, 2019 in Web Technology by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...