Analysis of standard mode and weird mode in browsers

黄舟
Release: 2017-10-27 10:28:42
Original
1977 people have browsed it

What are the browser’s standard mode and weird mode?

Standard mode:

means that the browser parses and executes the code in accordance with W3C standards. In this way, it can be rendered with the prescribed syntax, which can be compatible with various browsers and ensure the correct rendering. form display web page.

Weird mode:

uses the browser's own way to parse and execute code. Because different browsers parse and execute code differently, we call it weird mode.

Why is there still a weird mode?

Before the standardization of HTML and CSS was completed, each browser had its own different implementation of HTML and CSS parsing, and many old web pages were designed according to these non-standard implementations. of. After the HTML and CSS standards are determined, browsers must implement support for HTML and CSS in accordance with the standards on the one hand, and ensure backward compatibility with non-standard old web page designs on the other. Therefore, modern browsers generally have two rendering modes: standard mode and weird mode. In standard mode, the browser parses and renders the document according to HTML and CSS standards; while in weird mode, the browser parses and renders the document according to the old non-standard implementation.

How does the browser determine which rendering mode to use?

If you add <!DOCTYPE html>(Note: case insensitive) to your page, it is equivalent to turning on standards mode . That is, as shown in the following code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title></title>
  </head>
  <body>
  </body>
</html>
Copy after login

If omitted, the browser will use a rendering mode that does not meet certain standards.

Common differences between standard mode and weird mode

  • Handling differences in box model: The width and height of the standard CSS box model are equal to the height and width of the content area, and do not include padding and borders. However, the width and height of the box model implemented by browsers before IE6 are calculated by including padding. and borders. Therefore, for IE, the width and height calculation methods of the box model in weird mode and standard mode are different;

  • Vertical alignment of inline elements: Many early Browsers align images to the bottom border of the box that contains them, although the CSS specification requires that they be aligned to the baseline of the text within the box. In standards mode, Gecko-based browsers will be aligned to the baseline, while in quirks mode they will be aligned to the bottom. The most direct example is the display of pictures. In standard mode, the image is not aligned with the bottom border of the parent element. If you look carefully, you will find that there is a small gap between the image and the bottom border of the parent element. That's because in standard mode, images are baseline aligned. In weird mode, this problem does not exist.

The above is the detailed content of Analysis of standard mode and weird mode in browsers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template