自定义input选中框的样式

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>Document</title>
    <style>
        /* 设置input为占位的隐藏 */
        input {
            position: absolute;
            opacity: 0; /*设置透明度为0,不太建议隐藏*/
        }

        /* 位选中的样式 */
        input[type='checkbox'] + label::before {
            content: '\a0'; /*不换行空格*/
            display: inline-block;
            width: 22px;
            height: 22px;
            border-radius: 50% 50%;
            background: #ffffff;
            border: 1px solid #d8d8d8;
            text-indent: 6px;
        }

        input[type='checkbox']:checked + label::before {
            content: '\2713';
            background-color: #ff8200;
            color: #ffffff;
        }

        div {
            position: relative;
            vertical-align: top;
            line-height: 23px;
        }
    </style>
</head>
<body>
<div>
    <input type="checkbox" id="btn" class="checkbox"/>
    <label>按钮</label>
</div>
</body>
</html>
posted @ 2021-03-12 22:55  黑色外套  阅读(79)  评论(0)    收藏  举报