父元素响应单选框checked状态实例页面

回到相关文章 »

效果:

  • 选项1
  • 选项2
  • 选项3
  • 选项4
  • 选项5

代码:

CSS代码:
.wonder {
    padding-left: 0;
    margin: 0;
    list-style-type: none;
    color: #eee;
    box-shadow: 0 .6px, 0 -0.6px;
    -webkit-text-fill-color: #333;
}
.wonder li {
    line-height: 2.75rem;
    padding-left: 1rem;
    position: relative;
}
.wonder li:not(:last-child)::after {
    content: '';
    display: block;
    border-top: 1px solid;
    transform: scaleY(0.51);
    margin-top: -1px;
}
.wonder [type=radio] {
    -webkit-appearance: none;
    appearance: none;
    all: initial;
    position: absolute; left: 0;
    width: 100%; height: 100%;
}
.wonder [type=radio]:active {
    -webkit-tap-highlight-color: transparent;
    background: linear-gradient(#bbb1, #bbb1);    
}
.wonder .active {
    -webkit-text-fill-color: #009FF1;        
}
HTML代码:
<ul class="wonder">
    <li for="$1"><input type="radio" id="$1" name="item" checked>选项1</li> 
    <li for="$2"><input type="radio" id="$2" name="item">选项2</li> 
    <li for="$3"><input type="radio" id="$3" name="item">选项3</li> 
    <li for="$4"><input type="radio" id="$4" name="item">选项4</li> 
    <li for="$5"><input type="radio" id="$5" name="item">选项5</li> 
</ul>