元素前后追加元素
使用 伪类
::before
和::after
结合attr
可以在元素的前后添加内容。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>测试</title>
<style>
body {
background-color: #f5f5f5;
border: 1px solid #000;
}
p {
font-size: 20px;
color: red;
font-weight: bold;
text-align: center;
}
p::before {
content: attr(data-prefix);
font-size: 16px;
color: #333;
color: blue;
}
p::after {
content: attr(data-suffix);
font-size: 16px;
color: #333;
color: green;
}
</style>
</head>
<body>
<!-- 价格伪99.99,可以通过js截取,或者使用下面的方法都可以 -->
<p data-prefix="¥" data-suffix=".99">99</p>
</body>
</html>