Mellon
Mellon

Reputation: 38902

Why my CSS does not take any effect?

In my eclipse javascript project, I put both my test.html and test.css file under ProjectName\WebContent\ direcotry.

My test.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>UI TEST</title>
</head>
<body>
    <div id="header">header</div>

    <div id="container">
      <h1>content</h1>
      <p>My test.</p>
      <p class="last">...</p>
    </div>

    <div id="sidebar">
      <h1>sidebar</h1>
      <ul>
        <li>link one</li>
        <li>link two</li>
      </ul>
    </div>

    <div id="footer">footer</div>
</body>
</html>

my test.css:

@CHARSET "ISO-8859-1";
#header {
  background: #d7dabd;
}
#container {
  width: 100%;
  float: left;
  margin-right: -200px;
}
#sidebar {
  width: 200px;
  float: right;
}
#footer {
  background: #d7dabd;
  clear: both; 
}

But, the CSS does not take any effect on my page, what is the reason?

Upvotes: 1

Views: 933

Answers (2)

Tim
Tim

Reputation: 5943

You have to include the CSS in your HTML-File in order to make it work. Between <head> and </head> put the following:

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

Upvotes: 6

Gevious
Gevious

Reputation: 3252

You need to include the css file in your test.html file for the browser to read it.

...
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
  <link rel="stylesheet" type="text/css" href="test.css"> 
  <title>UI TEST</title>
</head>
...

Upvotes: 0

Related Questions