Open In App

Foundation CSS Switch Basics

Foundation CSS is an open-source and responsive front-end framework built by ZURB foundation in September 2011, that makes it easy to design beautiful responsive websites, apps, and emails that look amazing and can be accessible to any device. It is used by many companies such as Facebook, eBay, Mozilla, Adobe, and even Disney. The framework is built on Saas-like bootstrap. It is more sophisticated, flexible, and easily customizable. It also comes with CLI, so it’s easy to use it with module bundlers. It offers the Fastclick.js tool for faster rendering on mobile devices. 

Switch in general gives the user an option to select one of the two possibilities present. So a basic switch is one in which we can toggle it on or off. In Foundation CSS, the switch is nothing but a check-box markup which we use to create this style.



Foundation CSS Switch Classes: 

Syntax:



<div class="switch">
  <input class="switch-input" id="xy" type="checkbox" name="xy">
  <label class="switch-paddle" for="xy">
    <span class="show-for-sr">...</span>
  </label>
</div>

Note:

Example 1: This is a basic example illustrating basic switches created using Foundation CSS.




<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Foundation CSS Switch</title>
        <!-- Compressed CSS -->
        <link rel="stylesheet" 
              href=
        <link rel="stylesheet" 
              href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css"/>
  
        <!-- Compressed JavaScript -->
        <script src=
        </script>
        <script src=
        </script>
    </head>
    <body>
        <center>
          <h1 style="color:green;">GeeksforGeeks</h1>
          <strong>Foundation CSS Switch</strong>
          <br/><br/>
          <div class="switch">
            <input class="switch-input"
                   id="exampleSwitch" 
                   type="checkbox" 
                   name="exampleSwitch">
            <label class="switch-paddle" 
                   for="exampleSwitch">
              <span class="show-for-sr">GeeksforGeeks</span>
            </label>
          </div>
        </center>
        <script>
            $(document).foundation();
        </script>
    </body>
</html>

Output:

Foundation CSS Switch Basics

Example 2: This is a basic example that illustrates a  survey made using Foundation CSS switch.




<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Foundation CSS Switch Basics</title>
        <!-- Compressed CSS -->
        <link rel="stylesheet" 
              href=
        <link rel="stylesheet"
              href=
"//cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.min.css"/>
        <!-- Compressed JavaScript -->
        <script src=
        </script>
        <script src=
        </script>
    </head>
    <body>
        <center>
        <h1 style="color:green;">GeeksforGeeks</h1>
        <strong>Foundation CSS Switch Basics</strong>
        <br>
        <br>
        <p>For the Following questions below answer Yes/No</p>
        <ol>
            <li>
                <span>Do you like day over night.</span>
                <div class="switch">
                    <input class="switch-input"
                           id="exampleSwitch1"
                           type="checkbox" 
                           name="exampleSwitch1" checked>
                    <label class="switch-paddle" 
                           for="exampleSwitch1">
                    <span class="show-for-sr">GeeksforGeeks</span>
                    </label>
                </div>
            </li>
            <li>
                <span>You are hardworking over intelligent.</span>
                <div class="switch">
                    <input class="switch-input" 
                           id="exampleSwitch2" 
                           type="checkbox" 
                           name="exampleSwitch2">
                    <label class="switch-paddle" 
                           for="exampleSwitch2">
                    <span class="show-for-sr">GeeksforGeeks</span>
                    </label>
                </div>
            </li>
             <li>
                <span>Your mental strength is good</span>
                <div class="switch">
                    <input class="switch-input"
                           id="exampleSwitch3" 
                           type="checkbox"
                           name="exampleSwitch3">
                    <label class="switch-paddle" 
                           for="exampleSwitch3">
                        <span class="show-for-sr">GeeksforGeeks</span>
                    </label>
                </div>
            </li>
        </ol>
        </center>
        <script>
            $(document).foundation();
        </script>
    </body>
</html>

Output:

Foundation CSS Switch Basics

Reference: https://get.foundation/sites/docs/switch.html


Article Tags :