CSS3 quick start: one or three ways to import CSS

Three CSS import methods

According to the position of CSS style writing (or the way it is introduced), CSS style sheets can be divided into the following three categories:

  • Inline style sheet (inline style), also known as inline style
  • Internal style sheet (embedded)
  • External style sheet (linked)

Priority between the three: inline style>internal style>external style

1. External style sheet

There are two types of external style sheets: <link> link type and @import type. The priority between them follows the principle of proximity, and their characteristics are as follows:

  1. css is saved in the .css file
  2. Import using the <link> tag or @import in HTML

Features of Linked <link>:

  1. Belongs to XHTML, no compatibility issues
  2. Load CSS files to the page first

Features of import @import:

  1. Belongs to CSS2.1, lower version browser does not support
  2. Load the HTML structure first and then load the CSS file.

2. Internal style sheet

Features of the internal style sheet:

  1. Not applicable to external css files
  2. Put css in the <style> of the <head> tag in HTML

3. Inline style (not recommended)

Features of inline styles:

  1. Affect only one element
  2. Add in the style attribute of the HTML element

Sample source code and web page display

.html

<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>三种CSS导入方式</title>
	<style type="text/css">
		p{
    
    
			background: #EE6412;
		}
/*		@import "setbackground.css"*/
	</style>
	<link  type="text/css" rel="stylesheet" href="setbackground.css">
</head>

<body>
	<h1>标题</h1>
	<p style="background: #1FB1DD">这是一个普通的段落。</p>
	<p>这更是一个普通的段落。</p>
</body>
</html>

.css

@charset "utf-8";
/* CSS Document */
h1{
	background: #F4F924;
}
p{
	background: #10E90E;
}

Web page
Insert picture description here

Guess you like

Origin blog.csdn.net/xfjssaw/article/details/115270543