Home  >  Article  >  Web Front-end  >  About code comments in HTML

About code comments in HTML

零到壹度
零到壹度Original
2018-03-29 15:14:113701browse


This article mainly shares an article about code comments in HTML. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to have a look.

HTML Comments

In HTML code, the text between the 0f22cfdea9b4f9815ce45283dc15856e tags is Document comments, the content of the comments will not be displayed on the browser page. Comments are only visible when you open the document in a text editor, or with your browser's "View Source" option.

There are two types of comments in HTML, one is HTML code comment and the other is IE conditional comment.

1. HTML code comments

In a large document, comments are used to mark the beginning and end of the block, which can be easily searched, or you can use comments to prevent certain content from being displayed.

When writing a lot of code, it is a good habit to comment out key code. Commenting to explain the intention of a certain piece of code can help remind yourself or others who need to work on this website. Understand what this code does.

It is also a good habit to use comments to hide scripts, so that browsers that do not support scripts will not display the script as plain text. For example:

2, IE conditional comments

IE conditional comments (Conditional comments) are an extension of IE browser to HTML code comments. A kind of non-standard logical statement, which can flexibly import different html elements, such as style sheets, html tags, etc. for different versions of IE.

Conditional comments first appeared in IE5 and are supported by subsequent versions. Its syntax is an ordinary HTML comment. Browsers other than IE will ignore it as a comment. Therefore, it can pass W3C verification and will not affect other browsers.

The function of conditional comments is very powerful. It can perform if conditional judgment and decide whether to parse the content in the conditional comment based on whether the judgment result is true or false.

Conditional judgment starts with a05bb37b1d3a3736e4afc7736fdfd66c and ends with 1b771f47d72d900ba74308aee59557f0. It can be judged based on IE, non-IE, and the version of IE. The version number can be judged by the number, and the version number can be accurate to 4 decimal places. For example:

      /* 所有IE,无论哪个版本 */
    /* 如果IE版本是6 */

Conditional judgment also supports greater than (gt: greater than), less than (lt: less than), greater than or equal to (gte: greater than or equal), less than or equal to (lte: less than or equal), or (|), and (&), not (!), brackets. For example:

             /* 如果IE版本大于6 */
            / * 如果IE版本小于等于9 * /
          /* 如果IE版本是6或7 */
             /* 如果IE版本不是5.5 */
  / * 如果IE版本大于6,且小于等于9 * /

With the help of conditional comments, many IE compatibility issues can be solved. For example, versions below IE9 do not support the new HTML5 elements header, nav, aside, footer, etc. There are a large number of html5shiv scripts on the Internet that can solve this problem. Just download the corresponding script, and use IE conditional comments at the head of the page to let versions below IE9 load the script, so that these old browsers can support the new elements of HTML5.

You can also use the same method to solve CSS compatibility issues. For example, if IE6 does not support some new CSS features, you can write a CSS file specifically for IE6 and only let IE6 load it:

The good news is that starting from the IE10 version, conditional comments are no longer supported. This marks the beginning of IE's maturity and standardization, and Web designers no longer have to be troubled by IE's compatibility issues.

Related recommendations:

html comment specification

HTML code comments

HTML code comments

The above is the detailed content of About code comments in HTML. For more information, please follow other related articles on the PHP Chinese website!

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