CSS 修改 input 单选框选中的颜色

问题描述:

公司为了统一风格,需要把input 改成统一颜色,纯css修改

解决:

复制代码
<div class="address-list">
          <div class="address-list-item">
            <label class="radio" for="diyi" class="label">
              <input type="radio" name="address" value="1" id="diyi" style="float:left"><i></i>
              <div>
                <div class="shouhuo-info">汪汪 <span>17523459962</span></div>
                <div class="address-detail">北京市海淀区楼北京市海淀区楼</div>
              </div>
            </label>
          </div>
          <div class="address-list-item">
            <label class="radio" for="disan" class="label">
              <input type="radio" name="address" value="1" id="disan" style="float:left"><i></i>
              <div>
                <div class="shouhuo-info">汪汪 <span>17523459962</span></div>
                <div class="address-detail">北京市1楼北京市海淀区1楼</div>
              </div>
            </label>
          </div>
        </div>
复制代码

CSS代码:

复制代码
/* 单选换颜色 */
.radio {
  position: relative;
  display: inline-block;
  font-weight: 400;
  padding-left: 25px;
  text-align: left;
  width: 100%;
  display: flex;
}

.radio input {
  position: absolute;
  left: -9999px;
}

.radio i {
  display: block;
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  outline: 0;
  border: 1px solid rgb(133, 133, 133);
  background: transparent;
  border-radius: 50%;
  transition: border-color .3s;
  -webkit-transition: border-color .3s;
}

.radio input+i:after {
  position: absolute;
  content: '';
  top: 2px;
  left: 2px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #ee2e2e;
  opacity: 0;
  transition: opacity .1s;
  -webkit-transition: opacity .1s;
}

.radio input:checked+i:after {
  opacity: 1;
}
复制代码

修改之后:

 

posted @   沁猿春  阅读(5588)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示