Smooth iOS Style Switch In Pure CSS – vc-toggle-switch.css

Category: CSS & CSS3 , Form | December 23, 2019
Author:ViniChab
Views Total:6,838 views
Official Page:Go to website
Last Update:December 23, 2019
License:MIT

Preview:

Smooth iOS Style Switch In Pure CSS – vc-toggle-switch.css

Description:

The vc-toggle-switch.css transforms the standard checkbox into an iOS-style toggle switch with a gooey effect on switch handle.

How to use it:

1. Download and import the stylesheet vc-toggle-switch.css in the HTML page.

<link href="vc-toggle-switch.css" rel="stylesheet" />

2. The markup structure to create a toggle switch and define the on/off text in the data attributes:

<div class="vc-toggle-container">
  <label class="vc-small-switch">
    <input type="checkbox" class="vc-switch-input" />
    <span class="vc-switch-label" data-on="Yes" data-off="No"></span>
    <span class="vc-switch-handle"></span>
  </label>
</div>

3. Customize the switch.

<div style="
  /*Background color when it's turned off*/
  --vc-off-color: #d1d3d4;
  /*Background color when it's turned on*/
  --vc-on-color: #38cf5b;
  
  /*Animation speed and type*/
  --vc-animation-speed: 0.15s ease-out;
  /*Font used by the text*/
  --vc-font-family: Arial;
  /*The size used*/
  --vc-font-size: 11px;
  /*The font weight*/
  --vc-font-weight: 300;
  
  /*Font color when the switch is on*/
  --vc-on-font-color: white;
  /*Font color when the switch is off*/
  --vc-off-font-color: white;
  /*How far the OFF text is from the right side*/
  --vc-label-position-off: 12px;
  /*How far the ON text is from the left side*/
  --vc-label-position-on: 11px;
  /*Small switch width*/
  --vc-width: 50px;
  /*Small switch height*/
  --vc-height: 25px;
  /*Border radius for the handle*/
  --vc-handle-border-radius: 20px;
  /*Border radius for the box*/
  --vc-box-border-radius: 18px;
  /*Shadow for the handle*/
  --vc-handle-shadow: 1px 1px 5px rgba(0, 0, 0, 0.2);
  
  /*Handle color*/
  --vc-handle-color: white;
  /*Handle width*/
  --vc-handle-width: 15px;
  /*Handle height*/
  --vc-handle-height: 15px;
  /*The handle's width while the toggle is clicked*/
  --vc-onclick-width: 30px;
  /*Hadle's distance from the top*/
  --vc-handle-top: 5px;
  ">
  <div class="vc-toggle-container">
    <label class="vc-small-switch"> 
      <input type="checkbox" class="vc-switch-input" /> 
      <span class="vc-switch-label" data-on="Yes" data-off="No"></span> 
      <span class="vc-switch-handle"></span> 
    </label> 
  </div>
</div>

You Might Be Interested In:


Leave a Reply