All*_*raj 2 html css twitter-bootstrap bootstrap-4
我使用标签作为复选框的蒙版,并且在选中相应的复选框时需要更改标签的背景。这是我到目前为止所做的:
.viewbutton {
height: 48px;
width: 48px;
background-color: #FFFFFF;
border-radius: 50%;
margin: 0px 4px;
border: 0px;
border: 1px solid #CDCDCD;
cursor: pointer;
background-repeat: no-repeat;
background-position: center;
background-size: 24px;
position: relative;
display: inline-block;
}
#comparechk:checked+#comparebtn,
#editchk:checked+#editbtn,
#multiplechk:checked+#multiplebtn {
background-color: #005EFF;
outline: none;
}Run Code Online (Sandbox Code Playgroud)
<input type="checkbox" id="comparechk" class="chkhidden">
<input type="checkbox" id="editchk" class="chkhidden">
<input type="checkbox" id="multiplechk" class="chkhidden">
<label for="comparechk" id="comparebtn" class="viewbutton"></label>
<label for="editchk" id="editbtn" class="viewbutton"></label>
<label for="multiplechk" id="multiplebtn" class="viewbutton"></label>Run Code Online (Sandbox Code Playgroud)
+是相邻同级组合器,所以A + B表示直接跟随 的B元素,中间没有其他元素。A
你想要通用的兄弟组合器,~
#comparechk:checked ~ #comparebtn,
#editchk:checked ~ #editbtn,
#multiplechk:checked ~ #multiplebtn {
background-color: #005EFF;
outline: none;
}
Run Code Online (Sandbox Code Playgroud)
http://jsfiddle.net/8u031bom/3/