HTML, XHTML and CSS All-In-One for Dummies - Andy Harris [21]
Figure 2-6 shows the first two error messages. The first complains about where the tag is. The second message complains about the
The Oxen and the Wheels
Look carefully at the head and title tag pairs, and review the notes in the error messages, and you’ll probably see the problem. The
Fixing the title
If the title tag is the problem, a quick change in the HTML should fix this problem. oxWheels2.html shows another form of the page with my proposed fix:
Note: I’m only showing the parts of the page that I changed. The entire page is available on this book’s CD-ROM.
The fix for this problem is pretty easy:
1. Move the title inside the head.
I think the problem here is having the
2. Change the comments to reflect the page’s status.
It’s important that the comments reflect what changes I make.
3. Save the changes.
Normally, you simply make a change to the same document, but I’ve elected to change the filename so you can see an archive of my changes as the page improves. This can actually be a good idea because you then have a complete history of your document’s changes, and you can always revert to an older version if you accidentally make something worse.
4. Note the current first error position.
Before you submit the modified page to the validator, make a mental note of the position of the current first error. Right now, the validator’s first complaint is on line 13, column 6. I want the first mistake to be somewhere later in the document.
5. Revalidate by running the validator again on the modified page.
6. Review the results and do a happy dance.
It’s likely you still have errors, but that’s not a failure! Figure 2-7 shows the result of my revalidation. The new first error is on line 16, and it appears to be very different from the last error. I solved it!
Figure 2-7: Document type does not allow element “h2” here.
Solving the next error
One down, but more to go. The next error (refer to Figure 2-7) looks strange, but it’s one you see a lot.
The document type does not allow error is very common. What it usually means is you forgot to close something or you put something in the wrong place. The error message indicates a problem in line 16. The next error is line 16, too. See if you can find the problem here in the relevant code:
The Oxen and the Wheels
From Aesop’s Fables
After you know where to look, the problem becomes a bit easier to spot. I got sloppy and started the
tag before I finished the . In many cases, one tag can be completely embedded inside another, but you can’t have tag definitions overlap as I’ve done here. The has to close before I can start the tag.
has to close before I can start the tag.
This explains why the two main browsers displayed From Aesop’s Fables differently. It isn’t clear whether this code should be displayed in H1 or H2 format, or perhaps with no special formatting at all. It’s much better to know the problem and fix it than to remain ignorant until something goes wrong.
The third version — oxWheels3.html — fixes this part of the program: