How to style a checkbox using CSS

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

I am trying to style a checkbox using the following:

30条回答
  •  不知归路
    2020-11-21 05:07

    With pure CSS, nothing fancy with :before and :after, no transforms, you can turn off the default appearance and then style it with an inline background image like the following example. This works in Chrome, Firefox, Safari, and now Edge (Chromium Edge).

    INPUT[type=checkbox]:focus
    {
        outline: 1px solid rgba(0, 0, 0, 0.2);
    }
    
    INPUT[type=checkbox]
    {
        background-color: #DDD;
        border-radius: 2px;
        appearance: none;
        -webkit-appearance: none;
        -moz-appearance: none;
        width: 17px;
        height: 17px;
        cursor: pointer;
        position: relative;
        top: 5px;
    }
    
    INPUT[type=checkbox]:checked
    {
        background-color: #409fd6;
        background: #409fd6 url("data:image/gif;base64,R0lGODlhCwAKAIABAP////3cnSH5BAEKAAEALAAAAAALAAoAAAIUjH+AC73WHIsw0UCjglraO20PNhYAOw==") 3px 3px no-repeat;
    }

提交回复
热议问题