引入方式:
1.行内样式:行内样式也叫内联样式,使用style属性引入CSS样式
如:
<p style="color:red;font-size: 30px;">p段落通过行内样式引入CSS样式</p>
2.内联样式表:内部样式表在<head>标签里面使用<style>标签书写CSS代码。
如:
<head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>内部样式表</title> <!--内部样式表--> <style type="text/css"> div{ color:red; } </style> </head>
3. 外部样式表:外部样式表表示CSS样式不写在HTML代码中,而是单独写在扩展名为.css的样式表中。
HTML文件引用扩展名为.css的样式表,有两种方式:
(1)、链接式
如:
<link rel="styleSheet" type="text/css" href="CSS文件的路径(包括文件路径和css文件名)" />
(2)、导入式
如:
<style type="text/css"> @import url("style.css"); </style>
优先级:行内优先级最高,其他的就近原则,即谁离代码近,谁的优先级比较高。