一、:before的作用和用法
作用:用于在元素内容前面加上指定内容
用法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="test">测试</div>
</body>
</html>
<style>
.test{
width: 100px;
height: 100px;
background-color: antiquewhite;
}
.test:before{
content: '前面添加元素';
color: red;
}
</style>
二、:after的作用和用法
作用:用于在元素内容后面加上指定内容
用法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="test">测试</div>
</body>
</html>
<style>
.test{
width: 100px;
height: 100px;
background-color: antiquewhite;
}
.test::after{
content: '后面添加元素';
color: red;
}
</style>
三、:hover的作用和用法
作用:用于给元素添加鼠标划入效果
用法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="test">测试</div>
</body>
</html>
<style>
.test{
width: 100px;
height: 100px;
background-color: antiquewhite;
}
.test:hover{
color: red;
}
</style>