css五大选择器
一.类选择器:用.+名称定义的css样式类型,叫类选择器在class中引用
.comment{
background-color: #0bbb15;
color: white;
margin: 20px;
padding: 20px;
}
<div class=“comment">
二.id选择器:用#+名称定义的css样式类型,叫id选择器,在id中应用
#header{
background-color: #0a0a0a;
color: white;
text-align: center;
padding: 5px;
}
<div id=“header”>
三.派生选择器:根据文档的上下文关系来确定某个标签的样式叫派生选择器
li strong {
font-style: italic;
font-weight: normal;
}
<li><strong>我是斜体字。这是因为 strong 元素位于 li 元素内。</strong></li>
四.元素选择器
p {font-size: 30px; backgroud-color: gray;}
h2 {background-color: red;}
后面中所有p和h2的元素都使用上面定义的样式
<p>111</p>
<h2>222</h2>
五.属性选择器:属性选择器在css2中引入,使我们可以根据元素的属性及属性值来选择元素
[title]
{
color:red;
}
<h title=“hell”>hello</h>