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

CSS

Why doesn't this background image work?

ignore the parenthesis instead of brackets for posting purposes

So if I have this HTML

(body)
(div class="container clearfix")
all my content here
(/div)
(/body)

Why doesnt my background work on the container div (putting a backgroun image behind my entire container but not the entire viewport) with this css?

.container{
background-image: url(../img/aebackground.jpg);
 }

I know the path to the image is correct because I can apply it to the body and it works, but it doesnt work when I apply it to .container

9 Answers

Are your images in a folder? If so what is the name of it?

Also Keep the quotes in.

Its working now. I dont know what I did, I changed the background to the banner .jpg since i knew that worked and it worked. When I switched it back to the background jpg it worked. craziness

Thanks for troubleshooting with me though! I appreciate it.

Marshall

No probs.

You need to add the quotes to the beginning of the alt tag.

Hey thomas, I just had a bad copy paste, i edited my original post, mind looking at the issue?

Thanks!

You need to put it between quotes.

You need to put it between quotes.

Chase tried that still not working

Try this:

.container{
background: url('../img/aebackground.jpg');
 }

(div class="container clearfix") (cant get it to show this line with the brackets

        <div class="grid_10">
            <img src="img/aebanner.jpg" alt="Agnostic Effect CS:GO">
        </div>

        <nav class="grid_10 omega">
            <ul>
                <li><a href="#"><div class="button" id="newsbutton">News</div></a></li>
                <li><a href="#"><div class="button" id="matchesbutton">Matches</div></a></li>
                <li><a href="#"><div class="button" id="rosterbutton">Roster</div></a></li>
                <li><a href="#"><div class="button" id="forumsbutton">Forums</div></a></li>
                <li><a href="#"><div class="button" id="sponsorsbutton">Sponsors</div></a></li>
            </ul>
        </nav>
    </div>

with

body{
     background-color: black;
}
.container{
    background: url('../img/aebackground.jpg');
}

not working

Can you give a screenshot of your layout.

Hmm I think it has something to do with the container when I inspect element it only highlights the area at the top where the banner is, but doesnt go down to includes where my nav list is. Inspect element is making it look like my .container stops at my nav section even though nav is nested within .container... if that makes sense?

Do you know how to take a screenshot?

All image hosting is blocked from work...

So i set the body to white. I have one banner centered, then 20px of space then 6 nav buttons centered and inline

then in a p tag below that, the word BLAH.

If I do

.container{
    background-color: black;
}

The container properly turns black for its width up to the word blah since its the last content on the page. one the sides and below my container is still white like it should be.

if i do

.container{
background: url(../img/aebackground.jpg)
}

Everything stays white no background image, with or without quotes in that line. But if I apply that same line to body then everything is covered in the background image... doesnt matter if i do background-image: either

so confused

Is your css in a folder called css or something else like that?

yeah its in a css folder and linekd properly because I can change the background colors, just cant get the image to work. But it works on the body, which I dont want.

Have you tried using this? .container { background-image: url("../img/aebackground.jpg"); } I believe background-image is used more often for this purpose. Also you were missing quotes and a semi-colon :)

Sorry :) I was looking for some aid with CSS and thought I could help...a year ago :)