结果:
HTML代码:
<html>
<head>
<title>在HTML中使用CSS样式的几种方法</title>
<link rel='stylesheet' href='style.css'></link>
<style>
a{
background:green;
color:white;
}
p#third{
background:black;
color:white;
}
p.forth{
background:blue;
color:white;
}
</style>
<link href='box.css' type='text/css' ref='stylesheet'>
</head>
<body>
<p style='background:red;color:white'>第一种:内置到HTML标签的style属性中</p>
<a>第二种:在HTML的<head>标签中使用<style>标签</a></br>
<p id='third'>第三种:使用id选择器</p>
<p class='forth'>第四种:使用类选择器</p>
<p id='fifth'>第五种:在HTML的<head>标签中使用<link>标签来调用外部的CSS文件(id选择器)</p>
<p class='sixth'>第六种:在HTML的<head>标签中使用<link>标签来调用外部的CSS文件(类选择器)</p>
<table>
<tr><td>第七种:在HTML的<head>标签中使用<link>标签来调用外部的CSS文件(标签)</td></tr>
</table>
</body>
</html>
CSS代码:
#fifth{
background:#789ABC;
color:white;
}
.sixth{
background:#FECBA9;
color:black;
}<pre name="code" class="css">table{
background:#123456;
color:white;
}
源文件: