前端之CSS选择器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>01</title>
<style type="text/css">
/*css基本选择器*/
/*1.标签选择器*/
a{
/*清除a标签默认下划线*/
text-decoration: none;
color: #b0b0b0;
}
a:hover{
color: #fff;
}
/*2.类选择器,书写格式:.类名,选择的是共性*/
.box1{
width: 100%;
height: 40px;
background-color: #333;
}
/*3.ID选择器,书写格式:#ID名,选择的是特性*/
#count{
color: #b0b0b0;
margin: 0.5em;
}
/*4.组合选择器 比如重置ul,ol默认样式*/
ul,ol{
list-style: none;
}
/*4.通配符选择器 慎用 不相关标签也会被选中,影响加载效率*/
*{
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div class="box1">
<a href="javascript:void(0);">ropon</a>
<span id="count"></span>
</div>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>01</title>
<style type="text/css">
/*css高级选择器*/
/*1.后代选择器*/
.top-bar a{
/*清除a标签默认下划线*/
text-decoration: none;
color: #b0b0b0;
}
/*2.子代选择器,书写格式:xx>xx*/
.box1>p{
width: 100%;
height: 40px;
background-color: #333;
}
/*3.交集选择器*/
div{
color: red;
}
div.box1{
color: green;
}
/*4.属性选择器*/
form input[type='text']{
border: none;
border: 2px solid green;
font-size: 16px;
}
/*5.伪类选择器
a:link 未被访问过
a:visited 已访问过
a:hover 鼠标悬停的时候
a:active 鼠标按住的时候
*/
/*6.伪元素选择器 属性一定是content*/
p:before{
content: '$'
}
p:after{
content: '.'
}

</style>
</head>
<body>
<div class="box1">ropon
<div>luopeng</div>
<form>
<input type="text" name="user" id="user">
<input type="password" name="passwd">
</form>
<a href="">Ropon</a>
<p class="box1">
<span>Pengge</span>
</p>
</div>
</body>
</html>