我想切换red-background
类,以便当鼠标悬停在上时button-bullet
,它将更改background-color
为#FCC1C5
。
我不想使用,.btn.button-bullet:hover
因为当屏幕上只有一个项目符号元素时,我有一些jQuery逻辑会禁止删除按钮显示出来。
由于某种原因,当我时toggleClass("red-background")
,什么也没有出现。
我想可能是因为在CSS,我设定.btn.button-bullet
的background-color
到transparent
。因此,如果这是问题,如何background-color
在jQuery中覆盖?
的HTML
<div class="worksheet-problems">
<div class="row">
<div class="col-lg-7">
<div class="form-group">
<div class="input-group input-group-lg worksheet-problem">
<div class="input-group-btn">
<button type="button" class="btn btn-default button-bullet"> <span class="glyphicon glyphicon-one-fine-dot" aria-hidden="true"></span> </button>
</div>
<input type="text" name="Worksheet-Problem" class="form-control" placeholder="Problem..." aria-label="Write worksheet problem here">
<div class="input-group-btn">
<button type="button" class="btn btn-default button-add" aria-label="Add"> <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span> </button>
</div>
</div>
</div>
</div>
</div>
</div>
的CSS
.red-background{
background-color: #FCC1C5;
}
/*get rid of Boostrap default grey for buttons*/
.btn.button-add, .btn.button-bullet{
background-color: transparent;
}
jQuery的
$(document).ready(function() {
$(".worksheet-problems").on("mouseenter mouseleave", ".button-bullet", function() {
if ($(".worksheet-problems").children().length > 1) {
$(this).children(".glyphicon").toggleClass("glyphicon-one-fine-dot");
$(this).toggleClass("red-background");
$(this).children(".glyphicon").toggleClass("glyphicon-minus-sign");
}
});
});
问题:您的red-background
班级的特异性低于.btn.button-bullet
。
解决方案(添加更多特异性,并将其放置在具有透明背景的选择器之后):
.btn.button-add, .btn.button-bullet {
background-color: transparent;
}
.btn.red-background {
background-color: #FCC1C5;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句