无法覆盖CSS伪元素:before
Unable to override CSS pseudo element :before
我有几个无序的列表项,它们指定密码的规则,并使用字体真棒在所有列表项前面显示一个图标,当我点击按钮时,我有javascript调用来检查规则是否满足,根据条件,我必须更改字体真棒图标,请参阅下面的代码
li {
position: relative;
padding-left: 20px;
margin-bottom: 10px;
}
li:before {
position: absolute;
top: 0;
left: 0;
font-family: FontAwesome;
content: "'f056";
color: dimgray;
}
.myClass{
position: absolute;
top: 0;
left: 0;
font-family: FontAwesome !important;
content: "'f058" !important;
color: forestgreen;
}
要覆盖li:before
,我有空闲代码
$("#limsg").addClass("myClass");
我应该怎么做才能在运行时获得不同字体的图标?
您的代码是正确的,但要覆盖li:before,您需要在之前使用myClass:
.myClass:before{
position: absolute;
top: 0;
left: 0;
font-family: FontAwesome !important;
content: "'f058" !important;
color: forestgreen;
}
你可以查看plunkr了解详细信息。https://plnkr.co/S41mrN
相关文章:
- 无法覆盖CSS伪元素:before
- jQuery:如何选择所有具有:before或:after的伪元素
- 选择一个 CSS 选择器来动态设置元素的样式 ::before
- 如何在jquery中使用.before时对元素进行动画处理
- .before插入多个元素
- 使用 JavaScript 自动获取 ::before 元素的信息
- 如何使用 javascript 使用 ::before 选择器为元素设置高度
- 如何通过Javascript更改伪:before元素的内容值
- 如何删除使用before()方法添加的元素
- 有没有任何方法可以重置元素的CSS规则:after/:before
- 一种通过程序在元素及其元素之间传递不相关属性的方法:before
- CSS伪元素上的事件侦听器,例如::after和::before
- Jquery/JS-如何切换元素的:after,:before
- CSS或jQuery以访问元素的父级:before
- css伪元素的替代解决方案:IE6/7的before
- 检测元素的更改并将其设置回before
- 定义一个类's .click - Before元素有这个类
- 动态地对:before元素应用样式
- 基于php变量更改:before元素的背景颜色
- jQuery element.before()插入格式不正确的元素