嗨@Toby,idee是正确的,您必须使用[id=click-1]
和或[for=click-1]
选项1:
标记:
<div>
<input id="click-1" type="radio" value="1" name="clickMe" />
<label for="click-1">Click me!</label>
</div>
<div>
<input id="click-2" type="radio" value="1" name="clickMe" />
<label for="click-2">Click me!</label>
</div>
<div>
<input id="click-3" type="radio" value="1" name="clickMe" />
<label for="click-3">Click me!</label>
</div>
样式:
div {position:relative;margin: 20px 0 0 0; }
input[type=radio] {display:none}
div label {padding:0 0 0 25px;}
label:before{border-radius:20px; background:blue; content:''; display:block; position:absolute; left: 0; top: 0; height:20px; width:20px; opacity:0.2}
input[id=click-1]:checked + label[for=click-1]:before{background:red!important;}
input[id=click-2]:checked + label[for=click-2]:before{background:black!important;}
input[id=click-3]:checked + label[for=click-3]:before{background:green!important;}
演示:http: //jsfiddle.net/CsMat/3/
选项2:
标记:
<div>
<input id="click-1" type="radio" value="1" name="clickMe" />
<label for="click-1">Click me!</label>
</div>
<div>
<input id="click-2" type="radio" value="1" name="clickMe" />
<label for="click-2">Click me!</label>
</div>
<div>
<input id="click-3" type="radio" value="1" name="clickMe" />
<label for="click-3">Click me!</label>
</div>
样式:
div {position:relative;margin: 20px 0 0 0; }
input[type=radio] {display:none}
div label {padding:0 0 0 25px;}
label:before{border-radius:20px; background:blue; content:''; display:block; position:absolute; left: 0; top: 0; height:20px; width:20px; opacity:0.2}
input[id=click-1]:checked + label:before{background:red!important;}
input[id=click-2]:checked + label:before{background:black!important;}
input[id=click-3]:checked + label:before{background:green!important;}
演示:http: //jsfiddle.net/CsMat/4/
选项 3:
标记:
<input id="click-1" type="radio" value="1" name="clickMe" />
<input id="click-2" type="radio" value="1" name="clickMe" />
<input id="click-3" type="radio" value="1" name="clickMe" />
<div>
<label for="click-1">Click me!</label>
</div>
<div>
<label for="click-2">Click me!</label>
</div>
<div>
<label for="click-3">Click me!</label>
</div>
样式:
div {position:relative;margin: 20px 0 0 0; }
input[type=radio] {display:none}
div label {padding:0 0 0 25px;}
label:before{border-radius:20px; background:blue; content:''; display:block; position:absolute; left: 0; top: 0; height:20px; width:20px; opacity:0.2}
input[id=click-1]:checked ~ div label[for=click-1]:before{background:red!important;}
input[id=click-2]:checked ~ div label[for=click-2]:before{background:black!important;}
input[id=click-3]:checked ~ div label[for=click-3]:before{background:green!important;}
演示:http: //jsfiddle.net/CsMat/2/