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 trialJoy Ahmed
Courses Plus Student 9,687 PointsCan't fit an image to cover the background
I want to get an image to cover my background. I wrote the code as given in the video. Even tried several sizes for the image but it doesn't cover the background. Please, help.
Ting-Chieh Huang
3,387 PointsHey Joy try to add background-size:100%;
Joy Ahmed
Courses Plus Student 9,687 PointsDoesn't work Huang
3 Answers
Rich Bagley
25,869 PointsHi Joy,
Without seeing your code it's difficult to see the exact issue but this page from w3schools or this post on CSS Tricks should hopefully help.
-Rich
Joy Ahmed
Courses Plus Student 9,687 PointsHere's my code Rich html { height: 100%; background: url('img/full-page.jpg') no-repeat center; background-size: cover; }
Rich Bagley
25,869 PointsHi Joy,
Can you try the following please?
html {
background: url('images/full-page.jpg') no-repeat center center fixed;
background-size: cover;
}
Does it make any difference?
-Rich
Joy Ahmed
Courses Plus Student 9,687 PointsNo difference Rich... is image size a problem?
erdragerdragsson
Courses Plus Student 5,887 Pointstry this instead!
html {
background: url('images/full-page.jpg') no-repeat;
background-size: cover;
background-position: fixed;
}
Hope this helps!
Kind regards.
// Erdrag
Rich Bagley
25,869 PointsHi Joy,
What are you seeing? Is the image appearing fixed in the centre but just not filling the screen?
-Rich
Joy Ahmed
Courses Plus Student 9,687 PointsI guess... it's with the size of my pic. I have tried another image and it does work... can u help me with the image size
Rich Bagley
25,869 PointsHi Joy,
Not sure what to suggest I'm afraid as the code I posted works fine for me, even testing with a 350px wide by 80px high image.
The only other thing I can think of is that you have a background-color set on a div above which is preventing the image from showing as it is behind the div.
Sorry I couldn't be more help.
-Rich
Anya Coleman
2,995 PointsJoy your code ( html { height: 100%; background: url('img/full-page.jpg') no-repeat center; background-size: cover; } )
full-page.jpg change to full-bg.jpg image name (full-bg.jpg)
html { height: 100%; background: url('img/full-bg.jpg') no-repeat center; background-size: cover; }
Jaime Rios
Courses Plus Student 21,100 PointsI had the same issue with www.seducciondelta.mx it helped using the vh unit for the background. Here you can see another example. http://zurb.com/building-blocks/hero-image-with-text-and-image
Joy Ahmed
Courses Plus Student 9,687 PointsJoy Ahmed
Courses Plus Student 9,687 PointsHere is my code:
html { height: 100%; background: url('img/full-page.jpg') no-repeat center; background-size: cover; }