PDA

View Full Version : W3C validation doesn't like my stylesheet...


doggo18
04-26-2003, 11:15 AM
This is the header of my (all) html documents.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<TITLE>[title here]</TITLE>
<BASE TARGET="text">
<link rel="stylesheet" type="text/css" href="content.css" />
<SCRIPT TYPE="text/javascript" SRC="loader0.js"></SCRIPT>
<SCRIPT TYPE="text/javascript" SRC="mtmtrack.js"></SCRIPT>
</HEAD>
<BODY>


Except for the fact that I should get used to lowercase tags :P, the html validator of W3C keeps choking on my <link> tag. When I remove it, W3C validates my page OK, but as soon as I add it ANYWHERE in the head section (above or under script/base element), it suddenly starts complaining that my <HEAD> tag is not opened, and in result, begins to cry about <BODY> being there... Am I doing something wrong, since I can't seem to grasp it... (all urls are ok btw, no errors there)

Thanks in advance :)

BoR|S
04-26-2003, 02:27 PM
Hmmm... that's strange!
This is the header of all my pages, and it validates fine:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1255"></meta>
<link href="style.css" rel="stylesheet" type="text/css" />
<title>title goes here</title>
</head>
<body>

brothercake
04-26-2003, 04:19 PM
You need to decide whether you're using HTML or XHTML - your pages have an HTML doctype and as a result the parser spews at /> in your link tag - because it's invalid HTML. If you're working with XHTML, then fine, but your doctype (and the rest of your code) should reflect that.

You're also missing a charset element - like BoR|S's example has - (but nb you shouldn't use a windows charstet for the web; use ISO-8859-1, or another ISO code, or UTF-8)

doggo18
04-26-2003, 05:38 PM
Ah stupid... so this is what happens when you browse the web, and take over examples... Stupid, I kind of expected the /> ending was standard for HTML 4.01 tags without a closing tag. Guess I should read more careful next time.

Well, everything works fine now, but I have a few more questions.

First, what do you advice me (a hobby-homepagewriter) to use?
- XHTML 1.0 or HTML 4.01?
- Strict or Traditional?
- What is the replacement for the <base target="something"> tag in Strict (x)html? I don't fancy specifying my target over and over again.
- What encoding is preferred/best? UTF-8 or UTF-16? Or some ISO encoding?

Thanks :)

brothercake
04-26-2003, 05:44 PM
- XHTML 1.0 or HTML 4.01?

XHTML - HTML is outdated now; if you're just starting to learn you may as well start from the latest standards; it's not any harder to learn. Have you seen the w3schools tutorial - http://www.w3schools.com/xhtml/default.asp

- Strict or Traditional?

You mean strict or transitional - well, I'd say go for strict. It's more strict (obviously!) but it stands you in better stead for the future. Transitional is for when you need something that isn't available in Strict - such as the <embed> element for showing flash movies to netscape 4, or perhaps if you're converting an exisiting site to XHTML from HTML.

- What is the replacement for the <base target="something"> tag in Strict (x)html?

There isn't one; the target attribute is gone from XHTML strict - you shouldn't really be opening new windows at all, and the <iframe> element is also gone from Strict. It's a hot debate this one - this thread (http://www.codingforums.com/showthread.php?s=&threadid=18162) talked about it (among others).

- What encoding is preferred/best?

If you're only using latin charsets then ISO-8859-1 is fine. UTF-8 is arguably better because non-latin character sets can be encoded in it as well, so in a sense it's more flexible. In XML the default charset is UTF-8, but personally I specify ISO-8859-1 for everything (there was a reason; I think it had something to do with entity mappings; but I can't really remember). If you want to know more about charsets - I don't really know much more - you could start another thread about it if interested.


NB - since I've got your attention (;)) - the <table> element is for data - it's not for layout. Remember that :)

liorean
04-26-2003, 06:03 PM
Personally I'd say ISO-8859-1 is not the charset you should use. Unless you're using unicode (UTF-7, UTF-8, UTF-16, UTF-32, UCS) and you want to use a western latin charset, US-ASCII or ISO-8859-15 are the way to go.

Of course, I'd use UTF-8 for everything if I were you.


Oh, and if you want to use embed elements, don't use a W3C html doctype, but a custom one. There has never been an embed element in the official html specifications.



Also note the fact that the root element as specified in the DTD declaration must have the same case as the root element in the document - thus this isn't correct:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> and neither is this <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>

This is nothing the validator will notice, but there are stricter sgml user agents than the html validator.



As for what to chose, I think html4 strict is the best for just throwing together a document, while xhtml is the one to use if you want to create a document for other purposes than testing.

doggo18
04-26-2003, 06:40 PM
Originally posted by brothercake
- What is the replacement for the <base target="something"> tag in Strict (x)html?

There isn't one; the target attribute is gone from XHTML strict - you shouldn't really be opening new windows at all, and the <iframe> element is also gone from Strict. It's a hot debate this one - this thread (http://www.codingforums.com/showthread.php?s=&threadid=18162) talked about it (among others).

I hate popup windows, but that is not what I am using it for. It is mostly ment for the fact that my page is divided into frames, and that the different browsers interpret an <a> tag without TARGET or a page without <base target...> differently. IE might open it in the same frame; but other browsers (experienced it before, forgot browser and version tho) get rid of your frameset in the process, or they might open a new window.

Originally posted by brothercake
NB - since I've got your attention (;)) - the <table> element is for data - it's not for layout. Remember that :) [/B]

I don't recall saying anything about the <table> tag?! I don't use it for layout, I have proper HTML 4.01 on all pages, except for the pages I forgot to remove any /> for now. Oh and I still need to get everything lowercase. But that's all the errors I get, and none about tables for layout whatsoever.

Thanks for your replies, Brothercake and Liorean. I think I will be using HTML 4.01 Transitional, or perhaps XHTML 1.0 Transitional. (Anyone know of any tools to convert all your tags to lowercase? :P)

liorean
04-26-2003, 07:06 PM
I think HTML Tidy can do that - have a look at W3C (http://w3.org/).

giz
04-26-2003, 08:32 PM
That XHTML-style ending /> of the tag can play havoc when used in an HTML document, and the same error can also occur if the attributes aren't quoted, as in:

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

I see this error in many sites. The first / seen after <head> is unfortunately interpreted as being </head><body>.

So, don't forget to always "quote" all attributes. You never know when a problem may occur if you do not:

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

brothercake
04-27-2003, 02:18 AM
Originally posted by doggo18
It is mostly ment for the fact that my page is divided into frames

Ah well, that's different - there's another DTD just for framesets - have a look at http://www.codingforums.com/showthread.php?s=&threadid=18346

Originally posted by doggo18
I don't recall saying anything about the <table> tag?!
No you didn't; I take any excuse for standards propaganda :p

liorean
04-27-2003, 02:34 AM
Well, the frameset DTD replaces body with frameset - it shouldn't be used in the frames but only in the document containing the frameset. Use loose (transitional) in the frames.

giz
04-27-2003, 09:12 AM
>> Anyone know of any tools to convert all your tags to lowercase? <<

If you only have a few pages it can be done manually. This is how I did it. I copied all of the content of every HTML file into one long text file so I could change all at once. I used Wordpad to edit the file. I then used find and replace in the text editor to go through it all. With Wordpad, it isn't case sensitive on the find part so I could just do, FIND: <meta http-equiv and REPLACE: <meta http-equiv and it would do every instance of this. It is important to include a < or > or / or =" in the find and replace stuff, otherwise you might inadvertantly change some body content as well.

I had to do find and replace about 30 times to get all the tags that I used, without affecting any body content. I checked and then saved the file after each edit. When finished, I then cut and pasted small chunks (one HTML page worth at a time) of the long file back into into the respective individual HTML file, then ran each through the HTML validator. With a careful hand there were only a couple of typos in the whole lot.