有这么一段代码,按照思路,当你点击单选按钮的时候,div的背景色应该是这样的,但是不知为何并没有出现这种情况。一切看似简单,但并不清晰。我将不胜感激您的帮助!
.test{
height:100px;
width:100px;
background: #000;
}
.check-game-blue:checked + .test{
background: blue;
}
.check-game-red:checked + .test{
background: red;
}
<label class="drop"><input type="radio" name="check-game" class="check-game-blue" checked>Синий</label>
<label class="drop"><input type="radio" name="check-game" class="check-game-red">Красный</label>
<div class="test"></div>
input
从标签中取出并label
通过ID链接它们也就是给标签
label
加一个属性使其for
<label for="input_id">...</label>
为标签添加
input
一个属性id
以使其工作<input id="input_id" ...>
您
css
应该使用波浪号~
而不是加号+
。您可以在此处了解不同之处。