chrisgjh chrisgjh - 5 months ago 24
CSS Question

separate css file does not work on html file but put css in the same file as the html works

So I am reading a book called <>, when it comes to CSS the book asks readers to edit a style sheet in a separate .css file and put a link in the html file to link to the .css file. I did it but it does not work.

Then I watched a video clip on youtube that says I can simply add a tag in my html file to make css work and i succeed.

The problem is I want to do this in the way that the book taught me because I think that will make my file easier to read for my own sake.

here is my code for html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head><title>Hello</title></head>
<link rel="stylesheet" type="text/css" href="mycss.css" />
<body>
<p>Hi my name is chris</p>
</body>
</html>


here is my code for mycss.css:

p {
color:green;
font-family:arial;
}


however if i write it in this way, it works:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html>
<head><title>Hello</title></head>
<style type="text/css">
p {color:green; font-family:arial;}
</style>
<body>
<p>Hi my name is chris</p>
</body>
</html>

Answer

Try this... Make sure the link to the style sheet is in the head section of the html document:

<html>
  <head>
  <title>Hello</title>
  <link rel="stylesheet" type="text/css" href="mycss.css" />
  </head>
  <body>
    <p>Hi my name is chris</p>
  </body>
</html>
Comments