How to change the background color after checkbox is selected

UI design, must do this, click on the right side of the little red dot, and how to write the small red circle?

clipboard.png

Mar.21,2021


< html lang= "en" >

< head >

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
    .hide {
        display: none;
    }

    .square {
        background-color: -sharpfff;
        border: 1px solid -sharpbfbfbf;
        display: inline-block;
        height: 0.9em;
        padding: 2px;
        border-radius: 100%;
        margin-right: 5px;
        margin-top: -2px;
        vertical-align: middle;
        width: 0.9em;
        line-height: 1;
        box-sizing: content-box;
    }

    .hide:checked+.square:after {
        background-color: -sharpffd958;
        content: "";
        display: inline-block;
        height: 0.9em;
        width: 0.9em;
        vertical-align: top;
        border-radius: 100%;
    }
</style>

< / head >

< body >

<label>
    <input class="hide" type="radio" name="sex" id="tbb">
    <span class="square"></span>
    <span>b</span>
</label>
<label>
    <input class="hide" type="radio" name="sex" id="tbg">
    <span class="square"></span>
    <span>g</span>
</label>

< / body >

< / html >


the general component uses a background image, which you can see when reviewing elements, and then add class, separately to modify the background image under class


<span><div></div></span><a href="-sharp"></a>



     <span><div></div></span><a href="-sharp"></a>

        <script>
            
    window.onload = function(){
       
       var divs = document.getElementsByTagName("div"),
           spans = document.getElementsByTagName("span");

       
       for(var i = 0 ; i < divs.length ; iPP){
          
          spans[i].index = i;

          
          spans[i].onclick = function(){
              
          
          divs[this.index].style.background = "red";


          }


       }





    }

simply wrote one, which can be used as a reference.

Menu