Let's create a simple customized toggle switch using CSS. Initially when I was trying to create this, I founded it very confusing because many deve...
For further actions, you may consider blocking this person and/or reporting abuse
I have seen many toggle switches. But can you tell me how to design one which can resize easily. like it should have a size similar to the text element before it. If I change the pixels, things start falling apart. Can you write the css in terms of percentage or something and give an example on how to put it next to different sized texts. This would really be very helpful.
That's exactly what i thought and besides from that, none of those switches handles the actual label with text. So i played around and came up with this one:
codepen.io/nghh/pen/abWKXEK
You just need to edit these variables:
Cheers
yes! this is much better.
You could use EM units instead of PX! :) Then change the container's font-size to adapt the switch's size.
I don't know why but my label doesnt appear , and after trying my self i copied the code and it still not working ,i dont know why
Please share me your Codepen Pen link, I'll definitely look into it !
codepen.io/jlopy/pen/KKmeYBK
The css of the label is a copy paste of yours , I only did the firsts steps because its not working , thank you for be helpful
First of all, Thankyou for encountering this problem!
Reason
The main difference between your and my code is of Display property. Default property is
display:inline;
But I've used flexbox to make my button center to body, In this case body is
flex-container
and my<label>
isflex-item
and default display property of flex-items aredisplay:block
. And in your case<label>
isdisplay: inline;
Solution
Just add
display:block
in<label>
# Reference code is given below
I've also updated my code, Please let me know if you still having any problem.
My problem is solved , I didn't think that this was the problem , thank you so much
Using labels for the switch is very clever and avoids using javascript. Thanks for your tutorial. + 1
codepen.io/MaqboolS/pen/qBrwOoG here is something I made but it is not like the toggle switch with path instead its like dark mode/ light mode switch. Hope u all find it usefull
This is really good but you can also achieve the same with just input element without the label.
Overall, good technique 👍
You should remix this tortorial or post a codepen, I'd love to see it. I also have a few variations on this same type of toggle but I have it setup as a react component.
Here is mine (multi-version & animation in progress): codepen.io/istealersn/pen/abWKJbN
It is a nice post to learn
Nice post with pure css!
I made a similar pen about a year ago with background transition
codepen.io/Tyutyesz/pen/VwvNbbZ
👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏👏
Thank you very much for this CSS!
It works very well for an input...
What if there are 5 inputs in the form?
Thank you very much for this CSS!
It works very well for one input, but not with several...
What if there are 5 inputs in the form?