引出CSS以及它的三个选择器
引入CSS以及它的三个选择器
一:CSS的三种引入方式:
(1)内联属性 如下:
<p style="font-size: 10px; color:red">内容</p>
(2)写在style标签里
style标签一般写在head里 如下:
<head> <style> p { font-size: 12px; color:red; } </style> </head>
(3)用link标签引用外部文件 如下:
<link rel="stylesheet" type="text/css" href="../CSS/index.css">//后面加CSS文件名
二:CSS 选择器
(1)元素选择器
css代码: div { color: red; } html代码: <div> <p>内容</p> </div>
(2)类选择器
.show{ color: red; } 我们通过class属性,将这个类与html元素关联在一起。 <p class="show">内容</p>
(3)ID选择器
ID 选择器前面有一个 # 号,。形如: #show { color: red; } //这个ID对应着html标签的ID属性 <p id="show">内容</p>
建议CSS与html一起学习,这样很多东西就可以理解了。