使用JQuery更改CSS选择器之前的后台位置
我正在使用它来自定义单选按钮和复选框,但我需要更改:before
在单击元素的背景:before
。 可能吗?
HTML
CSS(无。)
.checkbox { display: inline-block; margin: 0 4px 0 0; cursor: pointer; text-align: left; padding: 0px; input { display: none; } &:before { background: url(/img/checkboxes.png) no-repeat; content: ""; float: left; height: 18px; width: 19px; margin: 0; } }
你不能用jQuery选择伪元素,我会说最干净的解决方案是使用jQuery操作元素的类:
.checkbox { display: inline-block; margin: 0 4px 0 0; cursor: pointer; text-align: left; padding: 0px; input { display: none; } &:before { background: url(/img/checkboxes.png) no-repeat; content: ""; float: left; height: 18px; width: 19px; margin: 0; } &.someclass:before { background-position:0 -55px; } }
然后:
$('.checkbox').addClass('someclass');