-
Notifications
You must be signed in to change notification settings - Fork 0
/
pseudo.classes.html
177 lines (163 loc) · 4.42 KB
/
pseudo.classes.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<meta name="renderer" content="webkit">
<title>css伪类</title>
<meta name="description" content="首页描述"/>
<meta name="keywords" content="首页关键词"/>
<meta name="author" content="Web Layout:amu"/>
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no"/>
<style>
.list li{color: orange;line-height: 24px;}
.list li:not(.end){color: blue;}
.list li:has(span){color: chartreuse;}
.list li:not(:last-child){
border-bottom: 1px dashed #ccc;
}
input{
height: 24px;
line-height: 24px;
padding: 3px;
}
form p{
position: relative;
}
input:focus{
outline: none;
}
input:valid{
border: 1px solid green;
}
input:invalid{
border: 1px solid red;
}
input::placeholder{
color: darkgoldenrod;
}
input:placeholder-shown{
border: 2px solid sienna;
color: sienna;
}
/*input:not(:placeholder-shown){
border: 2px solid silver;
}*/
.input-url + .input-label{
position: absolute;
color: darkgoldenrod;
pointer-events: none;/*元素经过状态失效*/
left: 5px;
top: 6px;
transform-origin: 0 0;
transition: all .3s;
font-size: 14px;
}
.input-url:placeholder-shown::placeholder{
color: transparent;
}
.input-url:not(:placeholder-shown){
border: 1px dashed violet;
}
.input-url:focus ~ .input-label,
.input-url:not(:placeholder-shown) ~ .input-label{
color: teal;
background: #fff;
transform: scale(0.75) translateY(-20px);
}
</style>
</head>
<body>
<h1>Effect without js</h1>
<h2>css伪类:not()/:has()/:last-child</h2>
<ol class="list">
<li><span>:has()草案,浏览器未实现</span></li>
<li>li:not(.end){color: blue;}</li>
<li class="end"><p class="e">:has(span)</p></li>
<li><p class="e">:has(span)</p></li>
</ol>
<style>
.target p{
position: relative;
display: none;
}
.target p:target{
background: palegoldenrod;
border: 1px dashed #ccc;
padding: 15px;
display: block;
}
.target p:target::before{
position: absolute;
left: 5px;
top: -15px;
content: '';
border-color: transparent transparent palegoldenrod transparent ;
border-width: 8px;
border-style: solid;
}
.centerblock{
position: absolute;
left: 50%;
top: 50%;
background: #fff;
transform: translate(-50%,-50%);
border: 2px solid gray;
padding: 20px;
}
div#open:target{
display: block;
}
.mask-layer{
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 9999;
display: block;
display: none;
background: rgba(0,0,0,.2);
}
</style>
<div class="target">
<h2>:target</h2>
<a href="#text1">第一段</a> |
<a href="#text2">第二段</a> |
<a href="#text3">第三段</a> |
<a href="#open">弹出层</a>
<p id="text1">我是第一段话,一</p>
<p id="text2">我是第二段话,二二</p>
<p id="text3">我是第三段话,三三三</p>
</div>
<div class="mask-layer" id="open">
<div class="centerblock">
<p>你可以不使用任何Javascript代码,只使用:target伪类创建一个加亮框。该技术依赖于初始化时就隐藏在页面中的链接到指定元素的锚。一旦定位,CSS就会更改其display 以便显示它们。</p>
<p style="text-align: right;"><a href="#">关闭</a></p>
</div>
</div>
<h2>表单伪类</h2>
<form action="">
<h4>验证通过:valid</h4>
<p>
<label for=""></label>
<input type="email" value="s@rr.com">
</p>
<h4>验证不通过:invalid</h4>
<p>
<label for=""></label>
<input type="email" value="srrcom">
</p>
<h4>placeholder显示和隐藏:placeholder-shown</h4>
<p>
<input type="datetime" value="" placeholder="请输入">
</p>
<h4>type='url'</h4>
<p>
<input class="input-url" type="text" value="" placeholder="输入连接地址">
<label class="input-label" for="">输入连接地址</label>
</p>
</form>
</body>
</html>