1:标签选择器
标签选择器,是所有带有某种标签的都生效。这里以p为例,也就是所有的带有p标记的都会这样的样式
实例:选择所有<p> 元素 :
<!DOCTYPE html>
<html>
<head>
<style>
p
{
background-color:yellow;
}
</style>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<div>
<p id=\"firstname\">My name is Donald.</p>
<p id=\"hometown\">I live in Duckburg.</p>
</div>
<p>My best friend is Mickey.</p>
</body>
</html>
2:id选择器
注意id选择器是唯一的,因为只有id="yy"的才有这种样式,而一个页面里元素的Id必须是唯一的,所以。。。你懂得id选择器以#开头用法是:id=""
实例:为 id="firstname" 元素添加指定样式:
<!DOCTYPE html>
<html>
<head>
<style>
#firstname
{
background-color:yellow;
}
</style>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<div class=\"intro\">
<p id=\"firstname\">My name is Donald.</p>
<p id=\"hometown\">I live in Duckburg.</p>
</div>
<p>My best friend is Mickey.</p>
</body>
</html>
3:类选择器.
类选择器以.开头,只要把元素的class="" 就能表现为这种样式了用法是:class=""
实例:
<!DOCTYPE html>
<html>
<head>
<style>
.intro
{
background-color:yellow;
}
</style>
</head>
<body>
<h1>Welcome to My Homepage</h1>
<div class=\"intro\">
<p>My name is Donald.</p>
<p>I live in Duckburg.</p>
</div>
<p>My best friend is Mickey.</p>
</body>
</html>
继续阅读与本文标签相同的文章
上一篇 :
CSS选择器种类及及其使用介绍
下一篇 :
为什么Win10的bug比Win7多了这么多?
-
健乐教学机器人可开展的教学实训内容
2026-05-14栏目: 教程
-
5G套餐曝光遭“吐槽”,iphone11受追捧,导致苹果11销量比较高
2026-05-14栏目: 教程
-
为什么修电脑的叫自己不要杀毒和清理垃圾?
2026-05-14栏目: 教程
-
当水乡建筑遇上机器人,成就乌镇又一网红景点
2026-05-14栏目: 教程
-
惊险!手刹失灵,郴州一货车开启“无人驾驶”模式……
2026-05-14栏目: 教程
