1

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:

  1. It should have been div.main
  2. and <link href="styles/main.css" type="text/css" rel="stylesheet"/>

3 Answers 3

2

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" />
Sign up to request clarification or add additional context in comments.

1 Comment

This answer is also correct but to solve the problem completely tjm's answer is also required -- stackoverflow.com/questions/4446669/…
2

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

@Braveyard This is also true. To target a 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.
I didn't know the space factor. Thanks.
This one is also true but I have only one option to mark as an answer.
0

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 -->

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.