Remove The Javascript From Toggling A Button
Here is the code that currently toggles a button. I would like to remove the javascript component of it by maybe using a checkbox. The only requirement I have is that I have to use
Solution 1:
As mentioned in your previous post, it cannot be achieved with only a checkbox because a checkbox cannot have content
, and thus, no pseudo elements ::before
or ::after
, since both operate on content
.
.togglerCheckbox {
display: none; }
.toggler {
width: 140px;
height: 40px;
background-color: #B3B3B3;
color: #FFF;
clear: both;
border-radius: 5px;
font-size: 12px;
/* new styles here: */padding: 00024px;
box-sizing: border-box;
display: inline-block;
position: relative;
line-height: 40px;
text-align: center;
cursor: pointer;
transition: padding .25s ease;
}
.togglerCheckbox:checked + .toggler {
padding: 024px00;
}
.toggler:before {
content: '';
display: block;
width: 20px;
height: 36px;
background-color: #4D4D4D;
position: absolute;
left: 2px;
top: 2px;
border-radius: 5px;
/* transition to make it look smoother */transition: left .4s ease;
}
.togglerCheckbox:checked + .toggler:before {
left: calc(100% - 22px);
}
<inputtype="checkbox"id="mycheckbox"class="togglerCheckbox" /><labelfor="mycheckbox"class="toggler">Text Value</label>
Post a Comment for "Remove The Javascript From Toggling A Button"