Ad

How To Create a Toggle Switch html and css -indicoderz


 Html

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta http-equiv="X-UA-Compatible" content="IE=Edge">

  <meta name="viewport" content="width=device-width, initial-scale=1">


  <title>HTML</title>

  

  <link rel="stylesheet" href="style.css">

</head>


<body>

 <div class="box">

  <input type="checkbox" name="" id=""/>

  <span></span>

 </div>

</body>

</html>

CSS

*{

 margin: 0;

 padding: 0;

}

body{

 background-color:#fff;

 

}

.box{

 transform: translate(150px,150px);

 position: relative;

 width: 90px;

 height: 40px;

 border: 2px solid #000;

 z-index: -2;

 border-radius:50px; 

}

.box input{

 width:100%;

 height: 100%;

 opacity: 0;

 cursor: pointer;

 

}

span{

 position: absolute;

 top: 2.5px;

 left: 2.5px;

 width: 35px;

 height: 35px;

 z-index: -1;

 border-radius:50px;

 transition: all 0.4s;

 background-color:red; 

}


.box input:checked~ span{

 transform: translateX(145%) scale(1);

 background-color: blue;

}

Post a Comment

Previous Post Next Post