在HTML中使用CSS的方法
行内样式
<p style="color:#FF0000";font-size:20px;text-decoration:underline;">正文内容1</p>
链接式
创建一个以css为后缀的文件
h2{
color:#000FF;
}
p{
color:#FF0000;
text-decoration:underline;
font-weight:bold;
font-size:15px;
}
导入html文件中
<html>
<head>
<title>页面标题</title>
<style>
@import url (test1.css);
</style>
</head>
<body>
</body>
</html>
内嵌式
<html>
<head>
<titke>页面标题</title>
<style>
p{
color:#0000FF;
text-decoration:underline;
}
</style>
</head>
<body>
</body>
</html>
优先级:行内样式>内嵌样式>导入样式
选择器
标记选择器
以 html 标签作为 css 修饰所用的选择器。
<style>
h1{
color:red;
font-size:25px;
}
</style>
class选择器
用于描述单一标签的样式。类选择器名称以一个点“.”号显示。
<style>
.red{
color:red;
font-size:18px;
}
.green{
color;green;
font-size:20px;
}
</style>
id选择器
id选择器可以为标有特定id的HTML元素制定特定的样式。
<style>
#bold{
font-weight:bold;
}
</style>
span标签
<span></span>标注行/标签内元素