自定义单选、复选框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale, minimum-scale=1, maximum-scale=1"/>
    <title>Title</title>
    <style>
        div {
            display: flex;
            justify-content: space-around;
        }
        .optionItem {
            width: 100px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            border-radius: 25px;
            overflow: hidden;
            box-shadow: 0 0 4px #3d6dd1;
        }
        .checkItem {display: none;}
        .optionValue {
            display: block;
            width: 100%;
            height: 100%;
        }
        .checkItem:checked + .optionValue {
            color: #fff;
            background: linear-gradient(132deg, #af62cf, #3f72df,#c26ce6);
        }

    </style>
</head>
<body>
<h3>单选.</h3>
<div>
    <label class="optionItem">
        <input type="radio"class="checkItem" name="radio" value=“选项值放这里”/>
        <span class="optionValue">option A</span>
    </label>
    <label class="optionItem">
        <input type="radio" class="checkItem" name="radio" value=“选项值放这里”/>
        <span class="optionValue">option B</span>
    </label>
    <label class="optionItem">
        <input type="radio" class="checkItem" name="radio" value=“选项值放这里”/>
        <span class="optionValue">option C</span>
    </label>
</div>
<h3>多选:</h3>
<div>
    <label class="optionItem">
        <input type="checkbox" class="checkItem" value="选项值,这里会被隐藏"/>
        <span class="optionValue">option A</span>
    </label>
    <label class="optionItem">
        <input type="checkbox" class="checkItem" value="选项值"/>
        <span class="optionValue">option B</span>
    </label>
    <label class="optionItem">
        <input type="checkbox" class="checkItem" value="选项值"/>
        <span class="optionValue">option C</span>
    </label>
</div>
<p><b>注:</b><small>input标签的checked属性值无论为何值,该选项都会被选中,单选则是最后一个</small></p>
</body>
</html>

自定义单选、复选框

上一篇:JQuery - 案例207:复选框:全选、全不选


下一篇:生活与工作