[英]CSS: Styled radio buttons not showing as selected
我有一些自定義單選按鈕,這些按鈕在單擊時未顯示為選中狀態。 確實會選擇實際的隱藏單選按鈕,但是由於某些原因,當我選擇新按鈕時,樣式顏色將不會出現。 誰能為為什么提供一些見識?
JSFiddle: http : //jsfiddle.net/dan5ermou5/f2aktvy4/1/
CSS:
/* /
/ CSS for A Place to Begin Section of Form /
/ */
#apbContainer {
position :relative;
height :702px;
width :233px;
top :-320px;
left :274px;
}
/* CSS for Text Boxes and Labels */
label {
display :inline-block;
cursor :pointer;
font-family :sans-serif;
font-weight :bold;
font-size :10pt;
margin-bottom :4px;
position :relative;
}
/* style radio button label */
#radioapb label {
font-family :sans-serif;
font-weight :normal;
font-style :italic;
font-size :10pt;
}
/* /
/ CSS for Radio Buttons /
/ */
/* remove old radio buttons */
input[type=radio] {
display:none;
}
.radio label:before {
content: "";
display: inline-block;
width: 14px;
height: 14px;
margin: 2px 0px 0px 0px;
position: absolute;
left: 115px;
bottom: 1px;
box-shadow: inset 0px 2px 3px 0px rgba(0, 0, 0, .3), 0px 1px 0px 0px rgba(255, 255, 255, .8);
border-radius: 20px;
}
.radio label:before {
border-radius :8px;
}
.radio input[type=radio]:checked + label:before {
content : "\2022";
color : green;
font-size : 14px;
text-align : center;
line-height : 22px;
}
HTML:
<body>
<!-- Client Check-in Form -->
<div id="apbContainer">
<form method="post" action="processcheck-in.php">
<input type="hidden" name="formID" value="check-inform"/>
<!-- A Place to Begin Radio Buttons -->
<div class="radio">
<div id="radioapb">
<label for="male">Male</label>
<input id="male" type="radio" name="GENDER" value="m"><br></br>
<label for="female">Female</label>
<input id="female" type="radio" name="GENDER" value="f"><br></br>
<label for="yhomeless">Yes</label>
<input id="yhomeless" type="radio" name="HOMELESS" value="y"><br></br>
<label for="nhomeless">No</label>
<input id="nhomeless" type="radio" name="HOMELESS" value="n"><br></br>
<label for="yveteran">Yes</label>
<input id="yveteran" type="radio" name="VETERAN" value="y"><br></br>
<label for="nveteran">No</label>
<input id="nveteran" type="radio" name="VETERAN" value="n"><br></br>
</div>
</div>
<input type="submit" name="dailyForm" value="Submit"/>
</form>
</div>
</body>
您的input
將放置在 label
,因此input:checked + label:before
無法使用。 相鄰的兄弟姐妹選擇器( +
)僅在第一個選擇器之后選擇兄弟姐妹。 因此,將<input>
放在<label>
之前。
我更新了您的jsFiddle: http : //jsfiddle.net/f2aktvy4/3/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.