Note : Solution has been appended to the answer at the bottom.
Okay, I've been doing it all the time but now it doesn't work.
Here is my folder structure which is so simple :
+ root |_ + styles |_ -main.css |_ + images |_ - background.jpg |_ - index.html
Here is the html code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<link href="styles/main.css" type="text/css"/>
</head>
<body>
<div class="main">
</div>
</body>
</html>
Css Code :
body
{
}
div .main
{
background-image:url(../images/main_background.jpg);
background-repeat:no-repeat;
height:950px;
width:897px;
}
The problem is : css file doesn't seem to be loaded and there is no css styles applied to class name main on the html file. That's really frustrating. I've also put them under IIS creating an Application under.
What could be wrong?
Thanks.
Solution:
Since the both answer should be at the same place to solve my problem, I decided to put complete answer here:
- It should have been
div.main - and
<link href="styles/main.css" type="text/css" rel="stylesheet"/>
3 Answers 3
You need to declare the rel attribute for the link for your CSS file, like so:
<link href="styles/main.css" type="text/css" rel="stylesheet" />
1 Comment
I think div .main in the css should read div.main. Note the lack of space.
With the space you are specifying child elements of divs, where the child has class main, without the space you are specifying divs with the class main.
3 Comments
div with a class main you need to use div.main or just .main. Using div .main would look for a div that has a child element with a class .main.Change the path from relative to absolute:
<link href="styles/main.css" type="text/css"/><!-- relative -->
<link href="/styles/main.css" type="text/css"/><!-- absolute -->