Я использовал свойство :checked
с оператором tilde(~)
, чтобы установить background & text
цвет при переключении.
.toggle{
position: relative;
display: inline-block;
}
.toggle input{opacity: 0; position: absolute; left: 0; top: 0}
.toggle i{
position: relative;
background: #fff;
color: #000;
height: 34px;
width: 50px;
display: flex;
justify-content: center;
align-items: center;
border: 1px solid #ccc;
border-radius: 4px;
font-style: normal;
transition: 350ms;
font-family: Arial;
}
.toggle input:checked ~ i{
background: blue;
border: 1px solid blue;
color: #fff;
}
.toggle i:before{
content: attr(data-swchoff-text);
}
.toggle input:checked ~ i:before{
content: attr(data-swchon-text);
}
<label class="toggle">
<input type="checkbox" name="screen" value="Profile" actionname="Profile">
<i data-swchoff-text="Off" data-swchon-text="On"></i>
</label>