通过css的attr获取绑定的数据
<div id="box" data-content-before=":before" data-content-after=":after">box盒子</div>
<style>
*{
padding: 0;
margin: 0;
}
body{
padding: 0;
margin: 0;
}
#box{
width: 200px;
height: 200px;
position: fixed;
top: calc(50% - 100px);
left: calc(50% - 100px);
background: #0877FF;
border-radius: 10px;
text-align: center;
box-shadow: 1px 2px 3px -1px;
}
#box:after{
content: attr(data-content-after);
position: relative;
top: -120px;
left: -160px;
width: 104px;
height: 100px;
line-height: 100px;
text-align: center;
border-radius: 10px;
background: orange;
box-shadow: 1px 2px 3px -1px;
display: block;
}
#box:before{
content: attr(data-content-before);
position: relative;
top: 0;
right: -260px;
width: 104px;
height: 100px;
line-height: 100px;
text-align: center;
border-radius: 10px;
background: #39c778;
box-shadow: 1px 2px 3px -1px;
display: block;
}
</style>