法一、js向目标元素插入style样式
css
.topo-db-float:before {
content: '';
position: absolute;
top: -6px;
left: 12px;
width: 10px;
height: 10px;
border-top: solid 1px #DCDCDC;
border-left: solid 1px #DCDCDC;
transform: rotateZ(45deg);
background-color: #fff;
}
js
$('.topo-db-float').append("<style>#dbFloatBox::before{top:93px}</style>");
通过上面代码可以给class为 topo-db-float 标签中top设置为93px。
转载:https://blog.csdn.net/qq_35565675/article/details/103596090
法二、动态添加类
css
.test1::after {
position: absolute;
width: 50px;
height: 50px;
background-color: aqua;
content: '';
left: -50px;
top: 0;
}
.test1.add::after{background-color: beige;}
js
$(".test1").addClass("add")