以下是代码。我需要的是当选择“女性”输入时更改.register-switch的背景颜色。 我想:当子输入检查时更改父div的背景颜色
input[value="Female"]:checked + .register-switch {
background: red;
}
,但它不工作。是否有可能在不使用JavaScript的情况下达到预期的效果?
.register-switch {
height: 32px;
margin-bottom: 20px;
padding: 4px;
background: lightblue;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.register-switch-input {
display: none;
}
.register-switch-label {
float: left;
width: 50%;
line-height: 32px;
color: #fff;
text-align: center;
cursor: pointer;
}
.register-switch-input:checked + .register-switch-label {
font-weight: normal;
color: #666;
background: #fff;
border-radius: 2px;
background-image: -webkit-linear-gradient(top, #fefefe, #eeeeee);
background-image: -moz-linear-gradient(top, #fefefe, #eeeeee);
background-image: -o-linear-gradient(top, #fefefe, #eeeeee);
background-image: linear-gradient(to bottom, #fefefe, #eeeeee);
-webkit-box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.1);
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.1);
}
<div class="register-switch">
<input type="radio" name="sex" value="Male" id="sex-m" class="register-switch-input" checked>
<label for="sex-m" class="register-switch-label">Male</label>
<input type="radio" name="sex" value="Female" id="sex-f" class="register-switch-input">
<label for="sex-f" class="register-switch-label">Female</label>
</div>
有在CSS没有父母选择(但)所以你必须要么改变HTML/CSS或使用JS。 – j08691
恐怕答案不是 – Chris