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

Background Image not showing up

I can't figure out why my background image is not showing up. I tried two different relative links cause i wasn't sure which one it was (this is all formatted with the brackets and such on the actual page)

background: url ('img/purple-dot.jpg') repeat;

and

background: url ('../img/purple-dot.jpg') repeat;

and cause i wasn't sure,

background: url ('/img/purple-dot.jpg') repeat;

the folder Is in my img folder and the img folder is in the same folder as my css, and index.html page.

the background color functions when I put it before the url, just not the Image!*

Here is my code:

CSS body { font-family: 'Averia Libre', cursive; color:#354B5E; background: #420600 url ('/img/purple-dot.jpg') repeat;

HTML

```<!DOCTYPE html> <html>

<head> <title>Website Practice One</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen"> <link href='http://fonts.googleapis.com/css?family=Averia+Libre:400,700,300italic' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/styles.css" type="text/css" media="screen"> </head>

<body> <div class="container clearfix">

    <nav class="grid_12"> 
        <ul class="nav"> 
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>```

ectera....

that came out really weird... the html is this
<html>

<head> <title>Website Practice One</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <link rel="stylesheet" href="css/grid.css" type="text/css" media="screen"> <link href='http://fonts.googleapis.com/css?family=Averia+Libre:400,700,300italic' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/styles.css" type="text/css" media="screen"> </head>

<body> <div class="container clearfix">

    <nav class="grid_12"> <!omega is used because margin needs to be zero pixels on the right. Each of the grids have margins on the right, because this div is the last elements in the columns, we need to remove it's margin so it doesn't get bumped down to the next line !>
        <ul class="nav"> 
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Portfolio</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>


    <div class="grid_12 omega">
        <h1> My First Webpage</h1>
            <p>What do you think?</p>

    </div>

        <section class="grid_12 omega"> 
            <h2> This is more about the webpage.</h2>
            <img src="" alt="" tite="">
                <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia, ligula in commodo lobortis, eros nisi tincidunt felis, non hendrerit velit nibh sit amet elit. Nunc consequat nunc sit amet ultricies condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed placerat gravida lectus sit amet aliquam. Mauris nisl purus, venenatis ac aliquam et, molestie a lectus. Mauris pellentesque ac est auctor pulvinar. Curabitur vulputate erat felis. Donec sit amet urna dignissim, sagittis odio sed, feugiat tellus. Cras porta velit non ante imperdiet vestibulum. Sed a cursus metus. Duis feugiat nec est eu tempus. Aenean non tortor lectus. Etiam nec diam in turpis vulputate vestibulum. Curabitur in ullamcorper nibh, facilisis elementum est. Etiam ornare blandit neque, ac luctus odio aliquet sed.</p>

        </section>

        <section>
            <div class="grid_9">
                <h2> This is even more about the webpage</h2>
                    <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia, ligula in commodo lobortis, eros nisi tincidunt felis, non hendrerit velit nibh sit amet elit. Nunc consequat nunc sit amet ultricies condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed placerat gravida lectus sit amet aliquam. Mauris nisl purus, venenatis ac aliquam et, molestie a lectus. Mauris pellentesque ac est auctor pulvinar. Curabitur vulputate erat felis. Donec sit amet urna dignissim, sagittis odio sed, feugiat tellus. Cras porta velit non ante imperdiet vestibulum. Sed a cursus metus. Duis feugiat nec est eu tempus. Aenean non tortor lectus. Etiam nec diam in turpis vulputate vestibulum. Curabitur in ullamcorper nibh, facilisis elementum est. Etiam ornare blandit neque, ac luctus odio aliquet sed.

                    Maecenas imperdiet, diam condimentum posuere luctus, ipsum est scelerisque felis, in pharetra nisi libero sit amet nisi. Vivamus dapibus dui et lacus congue, vitae auctor erat scelerisque. Morbi nec dictum eros. Quisque pellentesque sem ornare, dignissim velit quis, egestas nisi. Praesent aliquam ultricies sem, in malesuada leo ultricies ac. Nulla feugiat, neque dignissim laoreet lacinia, nunc justo pulvinar nisi, vitae porttitor justo magna non nulla. Pellentesque ut nisl bibendum risus feugiat pharetra. Praesent ultricies venenatis justo vitae sagittis. Ut bibendum ac tortor non congue. Aliquam non libero ac risus mollis consectetur. Proin tincidunt tempor turpis sed sollicitudin.</p>
                <h3> I'm saying more things</h3>
                    <p>Maecenas imperdiet, diam condimentum posuere luctus, ipsum est scelerisque felis, in pharetra nisi libero sit amet nisi. Vivamus dapibus dui et lacus congue, vitae auctor erat scelerisque. Morbi nec dictum eros. Quisque pellentesque sem ornare, dignissim velit quis, egestas nisi. Praesent aliquam ultricies sem, in malesuada leo ultricies ac. Nulla feugiat, neque dignissim laoreet lacinia, nunc justo pulvinar nisi, vitae porttitor justo magna non nulla. Pellentesque ut nisl bibendum risus feugiat pharetra. </p>
                </div>
            <aside class="grid_3 omega">
                <h2> This stuff is on the left</h2>
                    <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia, ligula in commodo lobortis, eros nisi tincidunt felis, non hendrerit velit nibh sit amet elit. Nunc consequat nunc sit amet ultricies condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
                <h2> There's even more stuff on the left</h2>
                    <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce lacinia, ligula in commodo lobortis, eros nisi tincidunt felis, non hendrerit velit nibh sit amet elit. Nunc consequat nunc sit amet ultricies condimentum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.</p>
            </aside>
        </section>


        <footer class="grid_12 omega">
            <p>Call me: 1-800-SHE-COOL
            <p>Follow ME on facebook &amp; twitter. </p>
            <a href="#"><img src="img/facebook.png"></a>
            <a href"#"><img src="img/twitter.png"></a>

        </footer>   
    <div>

</div>

</body> </html>

19 Answers

Tom Bedford
Tom Bedford
15,645 Points

I think the first one you listed is correct, however it looks like there is a space between "url" and the first bracket?

If your style.css and index.html are in the same folder with the image in a different folder:

body {
   background: #420600 url("img/purple-dot.jpg") repeat;
   /* this looks in the same directory as you are currently in for a folder called "img" and then the image file */
}

If your index.html is in a folder with separate folders for the css and images:

body {
   background: #420600 url("../img/purple-dot.jpg") repeat;
   /* this jumps up one folder, i.e. out for your "css" folder" and then goes into the "img" folder to find the image */
}

If your index.html, style.css and image are all in the same folder:

body {
   background: #420600 url("purple-dot.jpg") repeat;
   /* this looks for a file in the same folder as your .css file is in */
}

assuming body has been defined in the html aswell

not sure if its the problem but im pretty sure you don't need the first / in the url

Also look into you opening and closing tags, maybe you didn't paste the full code in but i can see something missing a closing tag :)

ill check out both. adam can you hint to me whereabouts you saw the open tag? I can't seem to find it.

within the CSS code you linked :)

I also don't think I quite understand the relative tags. I have all my folders css folder, img folder, index.html in a folder.... if i want to get to an image from that folder the relative tag is 'img/picture.jpg' or '/img/picture.jpg' OR '..img/picture.jpg'

It all depends on where you image in comparison to you html / css docs.

so if you have a folder with Index.html, style.css and a folder called 'img' then the link would be 'img/picture.jpg'.

if you had a folder with index.html, img folder and css folder that has your style sheet in then you will have to use the .. at the start to get back to the root folder.

Tom Bedford
Tom Bedford
15,645 Points

I've updated my answer to cover the different possibilities of where your image could be and explanations for where each code is looking.

Guil Hernandez
Guil Hernandez
Treehouse Teacher

Hey Juliet DeAmicis,

Take a look at Nick's article on this topic. It's really helpful. :)

Okay I fixed the brackets and I tried background: url('img/purple-dot.jpg) repeat; but its still not working! here's all my code, am I being an idiot somewhere?

CSS body { font-family: 'Averia Libre', cursive; color:#354B5E; background: #420600 url('/img/purple-dot.jpg') repeat; }

a{ color:#D74B4B; text-decoration: none; font-size: 2em; background: #DCDDD8 right top; padding: 15px 30px; /* padding on top bottom and right left (when its four values its top right bottom left) padding is when theres text and the square around the text expands. padding is inside the box*/ margin: 0px 0px; border-radius: 50px; /adds rounded corners the higher the value, the more curve the corners/ }

a:hover { background-color:#ff6969; }

ul.nav {/* we want to select the correct unordered list*/ margin:10px 0 0 0; list-style:none; float:right;

} ul.nav li {/selects all the list items in the nav bar/ float:left; margin-right: 40px; }

the italic bits haven't been commented out properly in the ul.nav li line.

Philip Allen
Philip Allen
8,171 Points

Hi Juliet

If you have a css folder with your stylesheet and another folder for your images then the correct path would be url('../img/purple-dot.jpg').

There is a really great article on this that should really help you understand. http://blog.teamtreehouse.com/how-to-fix-a-broken-image

Hope this helps.

Hmm I read the blog and checked everything...still broken. This is so weird. I even tried a different image, and I redid the file pathway to make sure it was correct. Could it be something that's cascading? I have a grid.css and a normalize.css file as well, but they're the same as given in the first tutorial on the website design track.

I deleted everything and further simplified. Here's what I have:

Html <!DOCTYPE html> <html>

<head> </head>

<body> </body>

</html>

Css

body { background-image: url('juliet.jpg'); }

My file is in the same directory as the css folder...instead of in an image folder. but it's still now working! It's also my own photo. Any ideas???

html <!DOCTYPE html> <html>

<head> </head>

<body> </body>

</html>

html <!DOCTYPE html> <html>

<head> </head>

<body> </body>

</html>

html <!DOCTYPE html> <html>

<head> </head>

<body> </body>

</html>

html <!DOCTYPE html> <html>

<head> </head>

<body> </body>

</html>

Philip Allen
Philip Allen
8,171 Points

the normalize.css shouldn't be a problem, especially as it should be placed before your own stylesheet as the cascade means that the code below. Simplest way to rule that out is to remove it.

I would suggest that you create a very simple html page and simple css file to test you have the correct path. Once you have that part working you can copy it back to your working files.

that's what i did and its still not working! I'm absolutely confuzules.

<head>
</head>
<body>
</body>
</html>

thats literally my html right now

Philip Allen
Philip Allen
8,171 Points

So you now have a folder with three files: index.html, styles.css and image.jpg?

your html should be

<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"/> </head> <body> </body> </html>

your css should be

body { background: url('image.jpg') }

if you place the stylesheet in a sub folder called css then your css file needs to change to

body { background: url('../image.jpg') }

if you then place the image in a folder called img the stylesheet needs to be

body { background: url('../img/image.jpg') }

if you place the image in the img folder but keep the stylesheet in the root folder then the css will be

body { background: url('img/image.jpg') }

still not working! heres' my code

<head>
    <link rel="stylesheet" href="styles.css" type="text/css"/> 
</head>

<body>
</body>

</html> ```

I checked to make sure they all matched!

CSS
body {
    background-image: url('juliet.jpg') repeat;
}

This may sound silly but is our css style sheet called styles.css or style.CSS?

This may sound silly but is our css style sheet called styles.css or style.CSS?