Internal style sheets are used when individual documents require specific styling
Suitable for case, short page development
<style>Define an internal style sheet in the head of the document using the tag
<style>The label can be placed anywhere, not necessarily <head>inside. The reason why it is placed <head>in it is to let the browser load CSS first when loading, so that the browser will know who wants to modify what style, and after loading it into html, it can directly give the style to the relevant object.
Advantages: Separation of structural styles, easy maintenance
Disadvantages: CSS styles can only be used in one page
External style sheets are ideal when styles need to be applied to many pages
Suitable for whole site development and relatively long page development
In the case of external style sheets, you can change the look of the entire site by changing one file. Each page uses <link>the tag to link to the style sheet. The browser will read the style declaration from the CSS file and format the document according to it.
advantage
Separation of structured styles, easy maintenance
Style reuse, can be used on multiple pages
<link>importThe difference between
In essence, <link>it is an HTML label, but importa way provided by CSS
load order
<link>When the page (the content inside the body) is loaded (that is, when it is browsed by the viewer), the <link>imported CSS will be loaded at the same time
importThe imported CSS will wait for the page to load before loading. If this loading method is used, there will be a flickering effect when the network speed is relatively slow, which will affect the user experience.
difference in compatibility
@importIt is provided by CSS2.1, so old browsers do not support it, @importonly IE5 and above can recognize it
<link>Labels don't have this problem
use DOM
When using JavaScript to control the DOM to change the style, you can only use <link>the tag
When using internal, external, and inline style sheets to modify the same tag at the same time, the inline style sheet has the highest priority, that is, the displayed result is an inline style
When external and internal style sheets are used at the same time, which css style is closest to the label will eventually display which style