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

HTML

Best practices for div background images

Hello everyone,

Just wondering if anyone has some advice when creating a div with a background image. I'm thinking of the www.shopify.ca website. The large image under the navigation adjusts to the size of the browser (to a point).

I like the idea of having a header image that takes up the width of the screen (mobile, tablet, desktop) and adjusts accordingly.

6 Answers

The easiest way is to use the CSS3 property background-size: cover;

You can read about that and several other ways to add a full page background image

Thanks, that's a huge help. I was lost in the internet for a couple hours trying to find a good answer. Thanks again.

Thanks Guil! Great video. What was the CSS for the white box you had over top of the background?

Guil Hernandez
STAFF
Guil Hernandez
Treehouse Teacher

Hi Brendan,

In the Quick Tip, you can see the CSS for it in the div rule. It's kind of meant to resemble a site "wrapper" or container.

I get into the cover and contain values in my Backgrounds and Borders Deep Dive.

ah okay, great. Thanks again. :)