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
Samir Amroun
675 PointsI don't know why, my CSS file have no effect on my html one, even though I have linked them together
here's the code I wrote a file called "main.css"
body {
background-color: orange;
}
I have linked it to an HTML file called "myname.html"
<head>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h1> samir amroun </h1>
</body>
I'm working on workspace and when I click on preview, the color of the background is still white.
I have tried to add the css directly to my html using <style> code
<head>
<link rel="stylesheet" href="css/main.css">
<style>
body {
background-color:orange;
}
</style>
</head>
<body>
<h1> samir amroun </h1>
</body>
and it's working, so I know it has something to do with my link code
thank you for your time
5 Answers
Philip G
14,601 PointsNo matter, I'm glad to help you. I think you forgot the doctype:
<!DOCTYPE html>
If not, add a title and check if your folder is named uppercase. You can post a link, then I can check it for you.
Ryan Romano
4,534 PointsIs the link to the CSS file within your HTML markup pointing to the correct place? Should it be relative instead of absolute?
absolute <link rel="stylesheet" type="text/css" href="mystyle.css"> relative <link rel="stylesheet" type="text/css" href="C:/Users/YourName/Desktop/CSS/mystyle.css>
Samir Amroun
675 PointsThank you very much Ryan for your time, but I did find a solution, thank you again.
Eivind Jonassen
5,994 PointsThis seems very much possible. Samir, have you created a folder called css and put your css-document inside, or have you created the css-document on the same level as the myname.html file?
In the first case your link should say:
<head>
<link rel="stylesheet" href="css/main.css">
</head>
In the second scenario your link should be:
<head>
<link rel="stylesheet" href="main.css">
</head>
If that is the case I think you should move it into a folder named css either way to organize your files.
Edit: Oh well, seems like you found an answer. Good for you! :)
Philip G
14,601 PointsPlease give me more information: A link and the whole Code of both files in backticks(Markdown Cheatsheet).
Samir Amroun
675 Pointsthank you for your time M. Phillip Graf, it's very much appreciated.
because it was not working, I have created a very simple code of a few lines each, but it still isn't working
I have created CSS file called "main.css"
body {
background-color: orange;
}
I have linked it to an HTML file called "myname.html"
<head>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
<h1> samir amroun </h1>
</body>
I'm working on workspace and when I click on preview, the color of the background is still white.
I have tried to add the css directly to my html using <style> code
<head>
<link rel="stylesheet" href="css/main.css">
<style>
body {
background-color:orange;
}
</style>
</head>
<body>
<h1> samir amroun </h1>
</body>
and it's working, so I know it has something to do with my <link> code
thank you again for your time Mister Phillip
Andrew Molloy
37,259 PointsWhat is your HTML code to import the css file?
Andrew Molloy
37,259 PointsIs your css file definitely inside of a folder called "css"?
Samir Amroun
675 Pointsyes it was, but I finally manage to find a solution thanks to Phillip Graf, thank you very much Mister Andrew Molloy, and I'm just a beginner and as such i did a very beginner mistake, thank you again for your time :D
Samir Amroun
675 PointsSamir Amroun
675 Pointsyeah thank you very much, it's finally working, damned I feel like such an idiot, sorry for having wasting your time on such a trivial matter, and thank you very much for the quickness and reliableness of your response.
Philip G
14,601 PointsPhilip G
14,601 PointsNo problem, glad to help!