其他分享
首页 > 其他分享> > CSS三种基本选择器

CSS三种基本选择器

作者:互联网

<!--    标签选择器:会选择到页面上的所有的这个标签的元素
-->
<style>
h1{
color: #4dbebe;
}
p{
font-size: 10px;
}
</style>
</head>
<body>
<h1>hello</h1>
<h1>hello</h1>
<p>world</p>

 

 

<!--    类选择器的格式     .class的名称{}
优点:可以多个标签归类,是同一个class,可以复用
-->
<style>
.green{
color: green;
}
.yellow{
color: yellow;
}
</style>
</head>
<body>
<h1 class = "green">hello</h1>
<h1 class= "yellow">world</h1>
<h1 class = "green">seeyou</h1>

 

 

<!--    id 选择器 :id必须保证全局唯一
#id名称{}
不遵循就近原则,固定的
id选择器>class选择器>标签选择器-->
<style>
#green{
color: green;
}
#blue{
color: #3ac479;
}
.yellow{
color:firebrick;
}
h1{
color: #681d9a;
}
</style>
</head>
<body>
<h1 id = "green">hello</h1>
<h1 id = "blue">world</h1>
<h1 class="yellow">see </h1>
<h1 class="yellow">you</h1>
<h1>tomorrow</h1>

 

标签:color,h1,yellow,--,green,三种,选择器,CSS
来源: https://www.cnblogs.com/weixiaoafanda/p/15867111.html