Forum Moderators: not2easy

Message Too Old, No Replies

External CSS not being read. Removing doctype fixes issue.

         

dotancohen

4:19 pm on Oct 24, 2009 (gmt 0)

10+ Year Member



I have a page that will not load external CSS. Tested in Firefox and Opera. If I remove the doctype then the CSS loads and affects the page. This is the HTML:

<!DOCTYPE HTML PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>Insert Notes</title>
<meta http-equiv='content-type' content='text/html; charset=utf-8' />
<meta http-equiv='cache-control' content='no-cache' />
<meta http-equiv='pragma' content='no-cache' />
<meta http-equiv='expires' content='0' />

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

</head><body>

<h1>Beer</h1>

<p>test</p>

</body></html>

And this is the CSS:


body{ background-color: gray;}
p { color: blue; }
h1{ color: white; }

swa66

6:08 pm on Oct 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should not modify the doctype

Stick to one from:
[w3.org...]

E.g. the xhtml1. transitional one is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The validator at [validator.w3.org...] usually will flag such problems.

dotancohen

7:11 pm on Oct 24, 2009 (gmt 0)

10+ Year Member



Thank you. Replacing the doctype with that one does not help, the issue persists. Here is the revised HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Insert Notes</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />

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

</head><body>

<h1>Beer</h1>

<p>test</p>

</body></html>

With that code, the CSS has no effect. Removing the doctype makes the CSS work. I have two test pages online, should I provide links?

dotancohen

7:24 pm on Oct 24, 2009 (gmt 0)

10+ Year Member



The problem was the css file being served as text/html. Changing it to text/css fixed the problem. I suppose the lacking doctype forced quirks mode, which was forgiving of the wrong content type.

rocknbil

7:27 pm on Oct 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you validate the CSS [jigsaw.w3.org]?

Removing, or an invalid, doctype causes Quirks Mode, There's nothing wrong with either snippet you posted, so it's either something else in your CSS or something in the server, or a caching issue?

Did you try this on a different server and domain?

dotancohen

9:06 pm on Oct 24, 2009 (gmt 0)

10+ Year Member



@rocknbil: the server was serving as text/html. Apparently Quirk Mode lets CSS served as HTML work as CSS, whereas non-QM does not.