伪元素练习( css动态设置文本内容)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>伪元素练习</title> <style> .box{ width:200px; height:200px; background-color:grey; float: left; margin-left:50px; margin-top: 50px; text-align: center; } /* 在a元素内容之前 */ .a::before{ content:attr(data-info); /* width:50px; height:20px; */ padding:2px 10px; line-height: 20px; text-align: center; background-color: hotpink; color:white; font-size:12px; } /* css动态设置文本内容 1:将文本内容作为信息插入到结构元素身上 属性名=属性值 统一属性名 data-* data-info data-star data-u 2:取信息 attr(data-*) */ </style> </head> <body> <div class="box a" data-inf="享八折"></div> <div class="box a" data-inf="减500元"></div> <div class="box"></div> </body> </html>
相关推荐
qiupu 2020-11-04
多读书读好书 2020-11-03
RedCode 2020-10-28
jiedinghui 2020-10-25
Ladyseven 2020-10-22
hellowzm 2020-10-12
zuncle 2020-09-28
Ladyseven 2020-09-11
jiedinghui 2020-09-07
xiaohuli 2020-09-02
葉無聞 2020-09-01
impress 2020-08-26
ThikHome 2020-08-24
nicepainkiller 2020-08-20
hellowzm 2020-08-18