CSS伪类元素中content的特殊用法attr
0 Views 前端 with
本文字数:300 字 | 阅读时长 ≈ 2 min

CSS伪类元素中content的特殊用法attr

0 Views 前端 with
本文字数:300 字 | 阅读时长 ≈ 2 min

这篇文章主要介绍了CSS伪类元素中content的特殊用法attr

Demo

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>
<head>
<meta charset="utf-8" />
<title>attr</title>
<style type="text/css">
.attr{
position: relative;
display:inline-block;
}
span:hover{
cursor:pointer;
}
span:hover:before{
content: attr(data-attr);
background: #2085c5;
border-radius: 3px;
color: #fff;
padding: 10px;
position: absolute;
left: 100%;
top:-70%;
margin-left: 8px;
white-space: pre;
}
span:hover:after{
content: "";
position: absolute;
width: 0;
height: 0;
border-right: 8px solid #2085c5;
border-top: 8px solid transparent;
border-bottom: 8px solid transparent;
}
</style>
</head>
<body>
<div class="attr">
<span data-attr = "鼠标效果tips">鼠标效果</span>
</div>
<script type="text/javascript">

</script>
</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
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>attr</title>
<style type="text/css">
.attr {
position: relative;
display: inline-block;
font-size: 80px;
color: #333;
overflow: hidden;
white-space: pre;
}

.attr:before {
display: block;
z-index: 1;
position: absolute;
top: 0;
left: 0;
width: 50%;
content: attr(data-content);
overflow: hidden;
color: #f00;
}
</style>
</head>

<body>
<span class="attr" data-content="前"></span>
<span class="attr" data-content="端"></span>
<span class="attr" data-content="博"></span>
<span class="attr" data-content="客"></span>
</body>

</html>

Sep 02, 2018
Apr 28, 2018