Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
On/off toggle buttons
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Markshall" data-source="post: 307222" data-attributes="member: 1872"><p>Not coded in a while and tried to do something similar to the toggle buttons on iOS, got far enough then got bored.</p><p></p><p>There's no parent element selector in CSS and I can't be bothered to use JavaScript to make the background colour of the onofftoggle element change to green when checked.</p><p></p><p>Anyway, you can view the preview here: <a href="http://codepen.io/Markshall/pen/vIqdg" target="_blank">http://codepen.io/Markshall/pen/vIqdg</a></p><p></p><p>And code is below:</p><p>[HTML]<!DOCTYPE html></p><p><html lang="en"></p><p> <head></p><p> <meta charset="UTF-8"></p><p> <title>Document</title></p><p> <style></p><p> body { padding: 60px; }</p><p></p><p> .onofftoggle {</p><p> width: 80px;</p><p> border: 1px solid #ccc;</p><p> border-radius: 25px;</p><p> height: 25px;</p><p> position: relative;</p><p> background-color: #f7f7f7;</p><p> }</p><p> </p><p> .onofftoggle input[type="checkbox"] {</p><p> display: none;</p><p> }</p><p> </p><p> .onofftoggle input[type="checkbox"] + .onoffbutton {</p><p> display: block;</p><p> background-color: #fff;</p><p> border: 1px solid #ccc;</p><p> border-radius: 25px;</p><p> width: 25px;</p><p> height: 90%;</p><p> max-height: 23px;</p><p> box-shadow: 0 2px 4px rgba(0, 0, 0, .3);</p><p> cursor: pointer;</p><p> position: absolute;</p><p> left: 0;</p><p> -webkit-transition: left .4s ease-in-out;</p><p> transition: left .4s ease-in-out;</p><p> }</p><p> </p><p> .onofftoggle input[type="checkbox"]:checked + .onoffbutton {</p><p> left: calc(100% - 25px);</p><p> }</p><p> </style></p><p> </head></p><p></p><p> <body></p><p> <div class="onofftoggle"></p><p> <label></p><p> <input type="checkbox" name="check1" /></p><p> <span class="onoffbutton"></span></p><p> </label></p><p> </div></p><p> </p><p> <div class="onofftoggle"></p><p> <label></p><p> <input type="checkbox" name="check2" /></p><p> <span class="onoffbutton"></span></p><p> </label></p><p> </div></p><p> </p><p> <div class="onofftoggle"></p><p> <label></p><p> <input type="checkbox" name="check3" /></p><p> <span class="onoffbutton"></span></p><p> </label></p><p> </div></p><p> </body></p><p></html>[/HTML]</p><p></p><p>Hope it helps if you go with it,</p><p>Mark.</p></blockquote><p></p>
[QUOTE="Markshall, post: 307222, member: 1872"] Not coded in a while and tried to do something similar to the toggle buttons on iOS, got far enough then got bored. There's no parent element selector in CSS and I can't be bothered to use JavaScript to make the background colour of the onofftoggle element change to green when checked. Anyway, you can view the preview here: [url]http://codepen.io/Markshall/pen/vIqdg[/url] And code is below: [HTML]<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> body { padding: 60px; } .onofftoggle { width: 80px; border: 1px solid #ccc; border-radius: 25px; height: 25px; position: relative; background-color: #f7f7f7; } .onofftoggle input[type="checkbox"] { display: none; } .onofftoggle input[type="checkbox"] + .onoffbutton { display: block; background-color: #fff; border: 1px solid #ccc; border-radius: 25px; width: 25px; height: 90%; max-height: 23px; box-shadow: 0 2px 4px rgba(0, 0, 0, .3); cursor: pointer; position: absolute; left: 0; -webkit-transition: left .4s ease-in-out; transition: left .4s ease-in-out; } .onofftoggle input[type="checkbox"]:checked + .onoffbutton { left: calc(100% - 25px); } </style> </head> <body> <div class="onofftoggle"> <label> <input type="checkbox" name="check1" /> <span class="onoffbutton"></span> </label> </div> <div class="onofftoggle"> <label> <input type="checkbox" name="check2" /> <span class="onoffbutton"></span> </label> </div> <div class="onofftoggle"> <label> <input type="checkbox" name="check3" /> <span class="onoffbutton"></span> </label> </div> </body> </html>[/HTML] Hope it helps if you go with it, Mark. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
On/off toggle buttons
Top