How to style a checkbox using CSS

前端 未结 30 3592
日久生厌
日久生厌 2020-11-21 04:26

I am trying to style a checkbox using the following:

30条回答
  •  旧时难觅i
    2020-11-21 05:03

    From my googling, this is the easiest way for checkbox styling. Just add :after and :checked:after CSS based on your design.

    body{
      background: #DDD;
    }
    span{
      margin-left: 30px;
    }
    input[type=checkbox] {
        cursor: pointer;
        font-size: 17px;
        visibility: hidden;
        position: absolute;
        top: 0;
        left: 0;
        transform: scale(1.5);
    }
    
    input[type=checkbox]:after {
        content: " ";
        background-color: #fff;
        display: inline-block;
        color: #00BFF0;
        width: 14px;
        height: 19px;
        visibility: visible;
        border: 1px solid #FFF;
        padding: 0 3px;
        margin: 2px 0;
        border-radius: 8px;
        box-shadow: 0 0 15px 0 rgba(0,0,0,0.08), 0 0 2px 0 rgba(0,0,0,0.16);
    }
    
    input[type=checkbox]:checked:after {
        content: "\2714";
        display: unset;
        font-weight: bold;
    }
     Select Text

提交回复
热议问题