Some time ago, the page in a project suddenly appeared garbled in IE6. I did various troubleshooting at that time, and finally speculated that it was a problem with the use of HTML5 DOCTYPE and Charset and Chinese comments, so I temporarily used the old Charset method to fix it. Later The garbled code never appeared again.
In fact, I have never been sure whether HTML5 Charset can be recognized by IE6, so I did some tests.
First, let’s talk about the two Charset declaration methods. In fact, everyone should be familiar with them:
We will refer to the first method as the HTML5 method and the second method as the HTML4 method.
Test environment:
Windows XP Sp2, Chinese version + English version of IE6, and IE9 under Windows 7 and its various compatibility modes and the current Stable version of Chrome, Firefox, etc.;
Because we use HTML files are all encoded in UTF8, so the HTML files in the test cases here are also in UTF8 (no BOM) format. The project is similarly encoded with gbk or gb2312.
Two methods are used for testing:
meta method: including HTML5 and HTML4 methods and their mashups
Server-side method: setting charset on the server side, nginx is used here, charset=utf-8
Test case—— Meta method:
UTF8
UTF8 HTML4 method
UTF8-GB2312
UTF8+ Chinese comment before meta
UTF8+ Chinese comment between HTML and HEAD
GB2312
GB2312 HTML4 method
GB2312-UTF8
GB2312+Chinese comments before meta
GB2312+Chinese comments between HTML and HEAD
Test case - server method:
Server setting encoding
meta encoding and server encoding are inconsistent
Each use case above can be accessed directly
Test results:
The test cases performed consistently in each browser;
UTF-8 solutions were all displayed normally;
charset was declared as gb2312, which was inconsistent with the UTF-8 encoding of the document, so all garbled characters;
1, 6 use HTML5 charset to define UTF8 and gb2312 respectively. 1 displays normally without garbled characters, and 6 has garbled characters - this is true for both the Chinese version of IE6 and the English version of IE6, indicating that IE6 can recognize the HTML5 charset;
1,2 use cases As with use cases 6 and 7, defining charset using HTML5 and HTML4 methods respectively has the same effect;
It is worth noting that the third use case first uses the HTML5 method to set the UTF-8 encoding, and then uses the HTML4 encoding setting. It is gb2312, but the page is displayed normally, while in the eighth use case, the result page displays garbled characters, so it can be inferred that the second meta tag does not take effect;
4 and 5 use cases are not garbled, indicating that simple HTML comments are not It will definitely lead to garbled characters. There is no test here about what may happen when loading external files such as js with different encodings in these two locations;
In the server method, use case 1 does not use meta to set charset, and the page displays normally, while use case 2 uses The meta setting charset=gb2312 is different from the server version, but there is still no garbled code, indicating that the charset returned by the server has a higher priority;
Conclusion:
In fact, regarding the specifications of charset, Google's development documents also explain it:
must be in the HEAD tag;
must be before any other content, that is, it must be at the front of HEAD;
including spaces and DOCTYPE declarations , should be within the first 512 bytes;
HTML5 and HTML4 have the same effect, just use one of them;
The above test also proves that item 4 is correct, and both writing methods are acceptable.
In addition, it is also a good idea to set charset on the server side. The charset statement is obtained directly in the HTTP response, which is more efficient and more convenient. Google is currently using this approach.
So as long as the page is written in a standardized way, there will be no problem of garbled characters. So you can boldly use HTML5's DOCTYPE and Charset declarations. But please try to follow the specifications in Google documents mentioned above. Don’t put too many things in the head, and put external resources such as js at the back.
It is inevitable that there will be omissions during the test. If there are any errors, please correct them and discuss them together~~

html5的div元素默认一行不可以放两个。div是一个块级元素,一个元素会独占一行,两个div默认无法在同一行显示;但可以通过给div元素添加“display:inline;”样式,将其转为行内元素,就可以实现多个div在同一行显示了。

html5中列表和表格的区别:1、表格主要是用于显示数据的,而列表主要是用于给数据进行布局;2、表格是使用table标签配合tr、td、th等标签进行定义的,列表是利用li标签配合ol、ul等标签进行定义的。

固定方法:1、使用header标签定义文档头部内容,并添加“position:fixed;top:0;”样式让其固定不动;2、使用footer标签定义尾部内容,并添加“position: fixed;bottom: 0;”样式让其固定不动。

html5中不支持的标签有:1、acronym,用于定义首字母缩写,可用abbr替代;2、basefont,可利用css样式替代;3、applet,可用object替代;4、dir,定义目录列表,可用ul替代;5、big,定义大号文本等等。

HTML5中画布标签是“<canvas>”。canvas标签用于图形的绘制,它只是一个矩形的图形容器,绘制图形必须通过脚本(通常是JavaScript)来完成;开发者可利用多种js方法来在canvas中绘制路径、盒、圆、字符以及添加图像等。

html5废弃了dir列表标签。dir标签被用来定义目录列表,一般和li标签配合使用,在dir标签对中通过li标签来设置列表项,语法“<dir><li>列表项值</li>...</dir>”。HTML5已经不支持dir,可使用ul标签取代。

3种取消方法:1、给td元素添加“border:none”无边框样式即可,语法“td{border:none}”。2、给td元素添加“border:0”样式,语法“td{border:0;}”,将td边框的宽度设置为0即可。3、给td元素添加“border:transparent”样式,语法“td{border:transparent;}”,将td边框的颜色设置为透明即可。

因为html5不基于SGML(标准通用置标语言),不需要对DTD进行引用,但是需要doctype来规范浏览器的行为,也即按照正常的方式来运行,因此html5只需要写doctype即可。“!DOCTYPE”是一种标准通用标记语言的文档类型声明,用于告诉浏览器编写页面所用的标记的版本。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools