johnsnow
2016-07-08 16:04
form {
border: 1px solid #ccc;
padding: 20px;
width: 300px;
margin: 30px auto;
}
.wrapper {
margin-bottom: 10px;
}
.box {
display: inline-block;
width: 30px;
height: 30px;
margin-right: 10px;
position: relative; /*就是这里*/
background: orange;
vertical-align: middle;
border-radius: 100%;
}
.box input {
opacity: 0;
position: absolute;
top:0;
left:0;
width: 100%;
height:100%;
z-index:100;/*使input按钮在span的上一层,不加点击区域会出现不灵敏*/
}
.box span {
display: block;
width: 10px;
height: 10px;
border-radius: 100%;
position: absolute;
background: #fff;
top: 50%;
left:50%;
margin: -5px 0 0 -5px;
z-index:1;
}
input[type="radio"] + span {
opacity: 0;
}
input[type="radio"]:checked + span {
opacity: 1;
}去掉就没法用了,这里到底是起到什么作用呢?
.box {
display: inline-block;
width: 30px;
height: 30px;
margin-right: 10px;
position: relative; /*就让.box下面的子元素相对于它来绝对定位,如果不加这个,那么.box下面的子元素就相对于html标签来绝对定位*/
background: orange;
vertical-align: middle;
border-radius: 100%;
}
.box input {
opacity: 0;
position: absolute;/*相对于父级含有 position属性的元素定位*/
top:0;
left:0;
width: 100%;
height:100%;
z-index:100;
}
出于对回答者的认同和尊重,解决了你的问题,请采纳,谢谢
十天精通CSS3
243143 学习 · 2677 问题
相似问题