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

CSS and HTML

l am trying to upload this image onto my background but it doesn't seem to be working whenever l refresh my browser. the html code is as follows: <!DOCTYPE HTML> <html> <head> <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 rel="stylesheet" href="css/futurelabs.css" type="text/css" media="screen">

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

the css: body { font-family: 'Nunito', sans-serif; font-weight: 100; font-size: 1.125em; color: #faf3bc; background: url("img/london.jpg") repeat; } h1 { color:orange; text-align:center; } p { font-family:"Times New Roman"; font-size:20px; }

what exactly am l doing wrong here? Nick Pettit

7 Answers

Chris Dziewa
Chris Dziewa
17,781 Points

Could you include your entire html file also if you type 3 backticks before with the name of the language and 3 backticks after your code, it will be formatted nicely. Do you see anything when it refreshes? With formatting:

<!DOCTYPE html>  
<html> 
   <head>
   </head> 
   <body>
    </body> 
</html>
Mike Bronner
Mike Bronner
16,395 Points

One thing that CAN mess some browsers up is if the DOCTYPE is off. In your case you might try how Chris wrote it: <!DOCTYPE html>. You'll notice the lowercase variation. If that doesn't fix it, please do post out your entire code so we can play with it on our machine. :)

with a few search online i change the whole html code to :

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

but this aint doing the trick eitrher

For some reason the browser wont post all my code on here :(

Mike Bronner
Mike Bronner
16,395 Points

HI Hackey, please post your entire code from the page you are working on.

'''<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <head> <link rel="stylesheet" href="css/futurelabs.css" type="text/css" />

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

Mike Bronner
Mike Bronner
16,395 Points

Looks like it didn't copy all your code. However, You need to get rid of the <?xml tag before the DOCTYPE. DOCTYPE must be the first thing on the page.

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

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

Mike Bronner
Mike Bronner
16,395 Points

Hackey, if there is no other code on the page, it won't display anything -- all you'll get is a white page. I'm assuming there is no other code, because each time you posted code, it only included the DOCTYPE, but no HTML. Please post the ENTIRE code you are working with in that file, if there actually is more. :)

there is i was trying to use the markdown cheatsheet but that aint working for me. well probz not using it well. its <!DOCTYPRE html><head><link rel="stylesheet" href="css/futurelabs.css" type="text/css" /></head><body></body></html>

Mike Bronner
Mike Bronner
16,395 Points

When marking up code in the forum, you want the opening line with the three apostrophes to stand on its own, then add code in the following line. Like so:

code

i keep trying but whenever i use the 3 backtips and try saving or posting i get an alert saying the page am looking for cant be found.

Mike Bronner
Mike Bronner
16,395 Points

Post your code to pastebin.com and share your link. :)

Mike Bronner
Mike Bronner
16,395 Points

I meant to escape it, but didn't work. Remove the dashes when doing it for real:

-- code --

Mike Bronner
Mike Bronner
16,395 Points

wow, that didn't work either :-|

but you get the idea:

  • escape sequence of 3 apostrophes
  • code on next line(s)
  • escape sequence of 3 apostrophes on last line

abit confused now is it the backtips or the apostrophes?

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

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

that aint working

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

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

ohh there we are ^^^^

the css code as follows

body {
    font-family: Georgia, serif;    /* default page font */
    background: #bbb url(./images/london.gif);
    margin: 0;          /* shorthand for all margins = 0 */
    padding: 0;         /* no padding */
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
Mike Bronner
Mike Bronner
16,395 Points

You're missing the opening HTML tag. The code should look like this:

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

    </body>
</html>

just tried that instead of it coming up with the picture i uploaded it comes up with a grey background

Mike Bronner
Mike Bronner
16,395 Points

Remove the "./" from the URL of the image in the CSS file.

Mike Bronner
Mike Bronner
16,395 Points

It's getting the gray background from #bbb, so we know it's working. But it can't find the image because of the "./" in front of the images directory. Should be:

background: #bbb url(images/london.gif);

thank you that worked :). one more issue though. it comes up with three different tiles of the image. how to i make this into one stretched image to fit the browser

Mike Bronner
Mike Bronner
16,395 Points

That is a whole other issue. Scaling background images is fairly complex and probably beyond the scope of the course you are taking at the moment. The following should provide some insight: http://stackoverflow.com/questions/5662735/stretch-background-image-css.

wont it work if i use the grid system and set the size to 960px?

Mike Bronner
Mike Bronner
16,395 Points

No, background images aren't limited by the size of the element they appear in. They will always display in their native size, unless specifically modified.

Chris Dziewa
Chris Dziewa
17,781 Points

Try using ``` background-repeat: no-repeat; background-size: cover;

in your body css. Also make sure you are using a larger resolution photo. the cover attribute will fill the body but it could distort the image if its resolution is too low. For more info about working with images head over to Guil's CSS Deep Dive when he talks about images.

that did worked thank you guys for your help this evening so much grateful Chris Dziewa and Mike Bronner

Chris Dziewa
Chris Dziewa
17,781 Points

Anytime man! Glad we could help.

Mike Bronner
Mike Bronner
16,395 Points

Yes, glad to hear that everything is working now. :) Best of luck!