Intellipaat Back

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

I have a background image in the following div, but the image gets cut off:

 <div style='text-align:center;background-image: url(/media/img_1_bg.jpg);background-repeat:no-repeat;width:450px;height:900px;' id="mainpage" align="center">

Is there a way to show the background image without cutting it off?

1 Answer

0 votes
by (40.7k points)

You can do it by using the background-size property, which is now supported by most of the browsers.

Try using the code given below to scale the background image to fit inside the div:

background-size: contain;

Use the below code to scale the background image to cover the whole div:

background-size: cover;

You can refer to these links for detailed information:

https://developer.mozilla.org/en-US/docs/Web/CSS/background-size

https://caniuse.com/#feat=background-img-opts

http://jsfiddle.net/grc4/wGRD7/

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...