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 trialHelloyellow Yellowhello
3,800 Pointswhy my background image does not show, in my banner class ?
main-banner{background-image: url("../img/leaf.jpg");}
<div class="main-banner">
<h1>This is the Main Banner Heading</h1>
<p>Andouille pork chop pancetta drumstick ground round beef ribs swine brisket ham.</p>
</div>
5 Answers
adamkemp
3,335 PointsHi Karam,
Have you defined the width and height of the div class main-banner? Try:
.main-banner {
background-image: url("../img/leaf.jpg");
background-size:cover; /*This makes the image the entire size of the div */
width:100%; /*This makes the width of the div 100% to it's parent */
height:10em; /*Change the height to your requirements */
}
Hope this helps
Adam
Helloyellow Yellowhello
3,800 PointsHI Adam i have done that, the only difference i noticed was the increase of the height but there is no image being displayed, just the height of the banner has increases as i defined the height
Zack Taylor
9,021 Pointskaram Oulad-Sbouria 90% of the time your find that the image is in the wrong place of your file structure. Take a look where you have placed this image. Your saying its in the img/ Folder. Tho for all you know you have gone down/up a level this is why its not showing.
your code: .main-banner{background-image: url("../img/leaf.jpg");} -Try- .main-banner{background-image: url("../../img/leaf.jpg");}
Good luck on your journey. I am sure your figure it out. If not message again I am sure someone might help or review videos again that might shine some light on your problem. :)
Terry Williams
12,469 PointsKarem,
I think Zack is right. It seems, based on what you have typed about your problem that the CSS styles are coming over just not your image source. If this is correct then I think your path to the file is incorrect. You can use your inspector window or Firebug to view your code and it will allow you to change the path and see where things need to point. Then just go and modify your CSS code.
Helloyellow Yellowhello
3,800 Pointshi terry i checked the path, i applied the style to my body tag and the path is fine it just doesn't work in my .main-banner class
.main-banner{background-image:url("../img/leaf.jpg"); background-size:cover; width:100%; height:10em;}
body{background-image:url("../img/leaf.jpg"); background-size:cover; width:100%; height:10em;}
Helloyellow Yellowhello
3,800 Pointsi can get it to work in the body tag for example
body{background-image: url("../img/leaf.jpg");}
but cant get it to work in my banner class for some reason i tried the z-index that didnt help either
adamkemp
3,335 PointsCheck to see if you have the correct link to your image.
If the image is in the same folder as your index page the link should be:
background-image: url("leaf.jpg");
If it is in an image (in this example a folder named img) folder on from your index page - the link should be:
background-image: url("img/leaf.jpg");
Hope this helps
Helloyellow Yellowhello
3,800 PointsHi Adam thanks for your response, i have checked my path, i applied the same css to the body tag, which works fine, but the image does not show in my main-banner class , i dont know what i am doing wrong ?
.main-banner{background-image:url("../img/leaf.jpg"); background-size:cover; width:100%; height:10em;}
body{background-image:url("../img/leaf.jpg"); background-size:cover; width:100%; height:10em;}
Helloyellow Yellowhello
3,800 Pointsi fixed it, it was due to my stupidity , that i was overlaying the background image with the color white after in my media queries that's why i could not see the image, thanks again i appreciate everyone's help
adamkemp
3,335 PointsGlad it's sorted.
Andrew Dushane
9,264 PointsAndrew Dushane
9,264 PointsYour code didn't come through readable. Check out the markdown instructions for posting code in a question. http://daringfireball.net/projects/markdown/basics