HTML5 新增了data-* 属性 可以在标签中定义我们的参数
而伪元素::before 或::after 可以直接接收data-*自定义参数
看效果图
在伪元素的content属性中 直接attr()括号内写接收参数
<body>
<div class="my" data-name="隔壁老王" data-car="小鹏P7">买了</div>
<style>
.my::before {
content: attr(data-name); //直接content(接收参数)
color: green;
}
.my::after {
content: attr(data-car);
color: silver;
}
</style>
</body>