原生实现常用的UI样式,持续更新...

单选框

<div class="radioBox">
 <input type="radio" id="1" name="selection" class="hiddenRadio"/>
 <span class="myRadio"></span>
</div>
.radioBox {
  display: inline-block;
  position: relative;
  width: 16px;
  height: 16px;
}
.hiddenRadio {
  display: inline-block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}
.myRadio {
  display: inline-block;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  border-radius: 50%;
  border: 1px solid lightgrey;
}
.hiddenRadio:checked+.myRadio {
  border: #007bff 1px solid;
}
.hiddenRadio:checked+.myRadio::before {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #007bff;
  content: '';
  top: 3px;
  left: 3px;
}

复选框

<div class="checkbox">
  <input type="checkbox" class="hiddenCheck" name="selection">
  <span class="trueMark"></span>
</div>
.checkbox {
  padding: 0;
  width: 16px;
  height: 16px;
  position: relative;
  display: inline-block;
}

.hiddenCheck {
  display: inline-block;
  position: absolute;
  margin: 0;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  opacity: 0;
}
.trueMark {
  display: inline-block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 1px solid #007bff;
  z-index: -1;
}
.hiddenCheck:checked+.trueMark {
  background: #007bff;
}
.hiddenCheck:checked+.trueMark::after {
  position: absolute;
  top: 2px;
  left: 2px;
  display: inline-block;
  width: 10px;
  height: 5px;
  content: '';
  border-bottom: 2.5px solid white;
  border-left: 2.5px solid white;
  transform: rotate(-45deg);
  z-index: -1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值