How to add the text “ON” and “OFF” to toggle button

前端 未结 6 1618
悲&欢浪女
悲&欢浪女 2020-12-01 03:30

On my project I wanted to add a text on my existing toggle code.So I wanted like this, When toggles ON it should display the text \"ON\" and display the \"OFF\" text if togg

6条回答
  •  悲哀的现实
    2020-12-01 04:14

    Have a look on this example

    .switch {
            width: 50px;
            height: 17px;
            position: relative;
            display: inline-block;
        }
    
            .switch input {
                display: none;
            }
    
            .switch .slider {
                position: absolute;
                top: 0;
                bottom: 0;
                right: 0;
                left: 0;
                cursor: pointer;
                background-color: #e7ecf1;
                border-radius: 30px !important;
                border: 0;
                padding: 0;
                display: block;
                margin: 12px 10px;
                min-height: 11px;
            }
    
                .switch .slider:before {
                    position: absolute;
                    background-color: #aaa;
                    height: 15px;
                    width: 15px;
                    content: "";
                    left: 0px;
                    bottom: -2px;
                    border-radius: 50%;
                    transition: ease-in-out .5s;
                }
    
                .switch .slider:after {
                    content: "";
                    color: white;
                    display: block;
                    position: absolute;
                    transform: translate(-50%,-50%);
                    top: 50%;
                    left: 70%;
                    transition: all .5s;
                    font-size: 10px;
                    font-family: Verdana,sans-serif;
                }
    
            .switch input:checked + .slider:after {
                transition: all .5s;
                left: 30%;
                content: "";
            }
    
            .switch input:checked + .slider {
                background-color: #d3d6d9;
            }
    
                .switch input:checked + .slider:before {
                    transform: translateX(15px);
                    background-color: #26a2ac;
                }

提交回复
热议问题