W3C validation is sometimes difficult to use, but with it you can see errors caused by layout design. The validator throws a lot of errors and warnings, indicating that your XHTML is not yet complete and may not function consistently across different browsers. The following ten subtle failure problems have stumped a large number of programmers, and we will tell you how to solve them. Before starting this article, I will introduce some issues that need to be paid attention to when using the W3C validator.
Don't worry about the warnings from the verifier - if the verifier says it found 12 errors and 83 warnings, ignore it and move on to the next step.
Correct one error at a time - Work in sequence, from top to bottom, correcting one error at a time. HTML is viewed from top to bottom with a browser, and these errors are displayed in the same order.
Refresh the code after each correction to make it valid again - a small mistake can often trigger a cascade of errors throughout the entire page. So if done incorrectly, "fixing errors" can also lead to more errors. Re-validating the code after each fix ensures that the problem is completely resolved.
Knowing the above basic exceptions, let’s take a look at several reasons why layout design is invalid.
1. The div tag is not closed. This is one of the most common reasons for layout design failure. It’s always surprising when we learn how many delicate layout designs fail because of this. Surveys show that open div tags are one of the most common section design errors and one of the most difficult to diagnose. The validator sometimes points to the wrong opening div tag, which can be like finding a needle in a haystack.
2. The troublesome embed tag In the early 1990s, Microsoft and Netscape browsers began to be able to recognize non-standard unique fonts. Unfortunately this means that the W3C validator does not yet recognize certain key HTML tags such as "embed", even though these tags are widely used. If you really want strict DOCTYPE (document type) validation, you can only give up nesting.
If you want effective layout and embedded media at the same time, you can try the Flash Satay method.
3. Improper DOCTYPE declaration Not declaring DOCTYPE, or incorrectly declaring DOCTYPE at the beginning of the file is also a common mistake. According to general experience, Strict DOCTYPE is the highest level of verification everyone pursues. Strict validation indicates that your web page will display optimally on all browsers. The Strict declaration code is as follows:
4. Trailing slash If your website cannot be verified, it is likely that the trailing slash is missing somewhere in the code. It's easy to overlook things like trailing slashes, especially in elements like image tags. For example:
This has no effect in strict DOCTYPE. To solve this problem, add "/" at the end of the img tag.
5. Align tag If the DOCTYPE is set to Transitional, you will use the "align" tag, but if you are more demanding and want Strict verification, you will see a lot of errors. Align is another tag that cannot be used for layout design. You can try using "float" or "text-align" instead of align to transform elements.
6. JavaScript
If Strict DOCTYPE has been declared, the CDATA tag needs to be overridden in JavaScript. This aspect of the verification process stumps many programmers, as websites tend to use embedded JavaScript for ads and tracking scripts. If JavaScript must be used, you can add the following tags before and after it:
7. Images require the “alt” attribute You may not have noticed, but images are also a potential stumbling block to advanced validation. In addition to the trailing slash, advanced validation also requires an alt tag to describe the image, such as alt= "Scary vampire picture".
Search engines also rely on alt tags to identify images on web pages, so it is always a good idea to add alt tags no matter what.
8. Unknown entity data Entity data is another common mistake that affects verification. We can consider using appropriate encoding characters to replace symbols such as "&". An entire list of appropriately encoded character entity data available in the XHTML section design.
9. Bad nesting Nesting means that the element contains the element Sweet!
It's easy to confuse the order of nested elements. For example, start the strong tag before the div tag, but then close the div tag first. This may not change the section layout, but it will invalidate your section design.
10. Missing "title" tag Although this seems like an obvious mistake, many programmers (myself included) often miss the title tag in the "head" section. When you see "missing a required sub-element of HEAD" (missing a required sub-element of HEAD), you will find that you forgot to add the title tag.