How to style a checkbox using CSS

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

I am trying to style a checkbox using the following:

30条回答
  •  执念已碎
    2020-11-21 05:04

    **Custom checkbox with css**  (WebKit browser solution only Chrome, Safari, Mobile browsers)
    
        
        
    
        /* The checkbox-cu */
    
        .checkbox-cu {
            display: block;
            position: relative;
            padding-left: 35px;
            margin-bottom: 0;
            cursor: pointer;
            font-size: 16px;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
    
    
        /* Hide the browser's default checkbox-cu */
    
        .checkbox-cu input {
            position: absolute;
            opacity: 0;
            cursor: pointer;
            height: 0;
            width: 0;
        }
    
    
        /* Create a custom checkbox-cu */
    
        .checkmark {
            position: absolute;
            top: 4px;
            left: 0;
            height: 20px;
            width: 20px;
            background-color: #eee;
            border: 1px solid #999;
            border-radius: 0;
            box-shadow: none;
        }
    
    
        /* On mouse-over, add a grey background color */
    
        .checkbox-cu:hover input~.checkmark {
            background-color: #ccc;
        }
    
    
        /* When the checkbox-cu is checked, add a blue background */
    
        .checkbox-cu input:checked~.checkmark {
            background-color: transparent;
        }
    
    
        /* Create the checkmark/indicator (hidden when not checked) */
    
        .checkmark:after {
            content: "";
            position: absolute;
            display: none;
        }
    
    
        /* Show the checkmark when checked */
    
        .checkbox-cu input:checked~.checkmark:after {
            display: block;
        }
    
    
        /* Style the checkmark/indicator */
    
        .checkbox-cu .checkmark::after {
            left: 7px;
            top: 3px;
            width: 6px;
            height: 9px;
            border: solid #28a745;
            border-width: 0 2px 2px 0;
            -webkit-transform: rotate(45deg);
            -ms-transform: rotate(45deg);
            transform: rotate(45deg);
            z-index: 100;
        }
    

提交回复
热议问题