自定义checkbox样式

效果图:
在这里插入图片描述 代码

text
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
// css
.radio {
    display: none;
}
.radio+label {
    display: inline-block;
    position: relative;
}

.radio+label {
    padding-left: 20px;
    box-sizing: border-box;
}
.radio+label:before{
    content: "";
    width: 14px;
    height: 14px;
    display: inline-block;
    position: absolute;
    transform: translateY(-50%);
    top: 50%;
    right: 0px;
}
.radio+label:before {
    width: 18px;
    height: 18px;
    left: 0px;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><circle cx="7" cy="9" r="7" transform="translate(1 -1)" fill="#FFF" stroke="#D9DBD9"></circle></svg>');
}

.radio[type=radio]:checked+label:before {
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><g transform="translate(2 2)" fill="none"><circle stroke="#C0E6FF" stroke-width="2" fill="#09F" cx="7" cy="7" r="8"></circle><circle fill="#FFF" cx="7" cy="7" r="2"></circle></g></svg>');
}
text
1 2 3 4 5 6 7 8 9
//使用
<h2>radio</h2>
   <div>
      <input id="label1" class="radio" type="radio" name="sex" checked>
      <label for="label1">男</label>
      <input id="label2" class="radio" type="radio" name="sex">
      <label for="label2">女</label>
   </div>

原文地址:https://blog.csdn.net/tian_tian_gong/article/details/86649754?ops_request_misc=&request_id=86e809fea7e5438eb011285d686a4b82&biz_id=&utm_medium=distribute.pc_search_result.none-task-blog-2~all~koosearch~default-8-86649754-null-null.142^v88^insert_down28v1,239^v2^insert_chatgpt&utm_term=css3%E7%89%B9%E6%95%88