Home>Article>Web Front-end> In what area of the document does the css stylesheet reside?

In what area of the document does the css stylesheet reside?

青灯夜游
青灯夜游 Original
2021-04-06 18:09:29 3358browse

The css style sheet resides in the "head" area of the document. Because if the CSS is placed at the bottom, the page can be rendered gradually, but after the CSS is downloaded and parsed, the text and images that have been rendered will need to be redrawn according to the new style, which is a bad user experience.

In what area of ​​the document does the css stylesheet reside?

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

css style sheets reside in the head at the top of the HTML document.

#why?

The href (HyperText reference) attribute in the link tag represents a hypertext reference. When CSS uses href reference, the browser will recognize it The document is CSS and is downloaded in parallel. It will not stop loading the current document. When loading HTML to generate a DOM tree, the DOM tree can be rendered at the same time. This can prevent flickers, white screens or confusing layouts.

In the most ideal situation, we hope that the browser will gradually render the downloaded CSS and gradually display the page to the user. However, in order to avoid re-rendering page elements when styles change, the browser blocks the gradual rendering of content. The browser waits for all styles to be loaded before rendering the page at once.

If the CSS file is placed at the bottom, the browser prevents the content from being rendered gradually. While the browser is waiting for the last CSS file to be downloaded, a "white screen" appears (white screen when a new connection is opened, and then Text appears first, images appear last, and styles appear last). This is very serious, because when the network speed is very slow, the CSS download time is relatively long, which naturally brings a "white screen" to the user for a long time, and the user experience is very poor.

Put the CSS at the bottom, and the page can be rendered gradually. However, after the CSS is downloaded and parsed, the text and images that have been rendered need to be redrawn according to the new style. This is a bad user experience. experience.

(Learning video sharing:css video tutorial)

The above is the detailed content of In what area of the document does the css stylesheet reside?. 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