Small external CSS file works in IE but not firefox?
I am learning HTML and want to use an external CSS for my site. I have created a very basic site and stylesheet and placed them in the same directory on my hard drive. The site opens in both Firefox and IE but Firefox ignores the stylesheet.
Can anyone tell me what I'm doing wrong? The HTML and stylesheet are shown below:
The HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" media="all"/>
</head>
<body>
<hr />
<p>This is a website with a style sheet!</p>
</body>
</html>
The stylesheet:
body
{
background-color:#d0e4fe;
}
h1
{
color:orange;
text-align:center;
}
p
{
font-family:"Times New Roman";
font-size:20px;
}
The style sheet is save in the file style.css
in the same directory as the HTML file, which is saved in a file called index.html
.
Thanks everyone for the help, but I have just discovered the problem. The file style.css was save in DOS format, I saved it in unicode format and it now works!
First, if your doctype is HTML4 and not XHTML, you shouldn't use the syntax, so:
<link rel="stylesheet" type="text/css" href="style.css" media="all"/>
should be
<link rel="stylesheet" type="text/css" href="style.css" media="all">
Second, your CSS file is probably not delivered as text/css (missing mime-type declaration for .css) by the web server you're testing it on. Does it fail too when you open your file locally?
If this is an Apache server, upload a .htaccess file containing this:
AddType text/css .css
链接地址: http://www.djcxy.com/p/30534.html
上一篇: 发布组织文件的问题