With checkbox to implement a custom radio

1, need to use adjacent sibling selector, pseudo-element selector, pseudo class selector

2, needs the characteristics label label: the user selects the tag, the browser will automatically focus to the label and the associated form controls.

Code Details:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .checkbox1{
            display: none;
        }
        .checkbox1 + i{
            display:inline-block;
            font-style: normal;
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: #c0c0c0;
        }
        .checkbox1:checked +i{
            background-color: hotpink;
        }
        .checkbox1:checked + i::after{
            content:' ';
            display:inline-block;  
            margin: 5px;    
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #fff;     
        }
    </style>
</head>
<body>
    <label>
        <input type="checkbox" class="checkbox1" >
        <i></i>
    </label>    
</body>
</html>

Did not select the previous renderings:

Here Insert Picture Description

After selecting renderings:

Here Insert Picture Description

Published 43 original articles · won praise 1 · views 3121

Guess you like

Origin blog.csdn.net/u011523953/article/details/104583721
Recommended