重置input類型為radio的默認樣式

默認的樣式如下圖:

inputradio01.png

修改為下圖樣式:

inputradio02.png

代碼如下(背景替換為需要的圖即可):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>重置input類型為radio的默認樣式</title>
        <style type="text/css">
            .reset-radio-wrap {
                display: inline-block;
                width: 100%;
                border: 1px solid #ededed;
                padding-left: 15px;
            }
            .reset-radio-wrap label {
                display: inline-block;
                padding: 5px 25px 5px 25px;
                position: relative;
                cursor: pointer;
            }
            .reset-radio-wrap label input[type=radio] {
                width: 16px;
                height: 16px;
                background-image: url(../img/radio_off.png);
                appearance: none;
                -webkit-appearance: none;
                outline: none;
                position: absolute;
                top: 50%;
                left: 0px;
                margin-top: -8px;
            }
            .reset-radio-wrap label input[type=radio]:checked {
                background-image: url(../img/radio_on.png);
            }
        </style>
    </head>
    <body>
        <div class="reset-radio-wrap">
            <label>
                <input type="radio" name="sex" value="male" />
                <span>男</span>
            </label>
            <label>
                <input type="radio" name="sex" value="female" />
                <span>女</span>
            </label>
        </div>
    </body>
</html>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容