Home  >  Article  >  Backend Development  >  Ten common reasons why CSS is invalid in Div+CSS web page layout

Ten common reasons why CSS is invalid in Div+CSS web page layout

巴扎黑
巴扎黑Original
2016-11-08 10:44:001537browse

Ten common reasons why CSS is invalid in Div+CSS web page layout
We learn the knowledge of Div+CSS web page layout, but Band of Brothers validation is sometimes difficult to operate, but with it you can check the errors caused by the layout design, the validation program throws a lot of Errors and warnings indicate that your XHTML is not yet complete and may not maintain consistent functions on different browsers. The following ten subtle failure problems have stumped a large number of programmers. This article will tell you how to solve them. Before the start of this article, I will introduce some issues that need to be paid attention to when using the basic div+css verification program of Brothers in Arms PHP training.

 1. Don’t worry about the warnings from the verification program: If the verification program says it found 12 errors and 83 warnings, ignore it and continue to the next step.
2. Correct one error at a time: Work in sequence, from top to bottom, and correct one error at a time. HTML is viewed from top to bottom with a browser, and these errors are displayed in the same order.

  3. Refresh the codes after each code correction to make them effective again: a small error often triggers a series of errors on the entire page. So if done incorrectly, "fixing errors" can also lead to more errors. Make the code valid again after each correction, so as to ensure that the problem is completely solved. Knowing the above basic exceptions, let's take a look at several reasons why the 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. Open div tags are one of the most common layout design mistakes and one of the hardest 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) verification, 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. Regarding the declaration of DTD document types, you can refer to the relevant articles at www.lampbrother.net.

 4. Ending Slash
If your website cannot be verified, it is very likely that the ending slash is missing somewhere in the code. It's easy to overlook things like trailing slashes, especially in elements like image tags. This has no effect in strict DOCTYPE. To solve this problem, add "/" at the end of the img tag.

5. Align tag
If DOCTYPE is set to Transitional, you will use the "align" tag, but if you are more demanding and want to get 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, you need to override the CDATA tag 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 that images are also a potential stumbling block for advanced verification. In addition to the trailing slash, advanced validation also requires the use of alt tags to describe images, such as alt= "Scary vampire picture". Search engines also rely on alt tags to identify images on web pages, so it is always good to add alt tags no matter what.

 8. Unknown entity data
 Entity data is another easy 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 elements are included within elements, and it is easy for us 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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn