Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ryan Canty
Courses Plus Student 5,665 Pointshow can I make my background image fill up the whole width of the screen and resize when I resize my browser?
I want to make my image take up the whole width of my screen, and when I resize the browser I want the image to resize as well. how can I do this?
1 Answer
Marco Caruso
5,208 PointsI agree with William. You can go about this a couple ways but the easiest would be to target the body element in your css and link an img. Check out these 2 links they will explain it in much greater detail and they're not that long.
body {
background-image: url("img.gif");
}
check this out to get an idea of how your image will scale with the body div -- https://www.w3schools.com/css/css_rwd_images.asp
and how you display images in your divs -- https://www.w3schools.com/cssref/pr_background-image.asp
William Smith
4,560 PointsWilliam Smith
4,560 PointsHello Ryan,
You can make your image cover the entire container that it is in by using background-size: cover in your css.
You can learn more about cover here
Hope this helps.
Will