Simple Activate / De-Activate switch using Simple Css

In this section i want to explain about how to create simple activate deactivate switch using the simple css3. Here we design the buttons with the help of css3. The button design css code is below

.switch {
position: relative;
display: inline-block;
width: 75px;
height: 34px;
}

This code is used to design the button you can change here height and width of the switch / button. Inside the button we have one slider circle the following code is used to create that white circle inside the button.

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}


Normal position of the switch is in red. When you clicked it turns in to green that means active status when you clicked again it turns in red that means de-active status. that will be done below css code.

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
-webkit-transition: .4s;
transition: .4s;
}

input:checked + .slider {
background-color: green;
}

This is very useful you can use this activate and deactivate button in several web applications. It is very simple and nice and also you can create this using simple css3 code. Here is the full code available. you can download the code and use it your projects. And also provided demo page, please checkout the demo page then you can know how the buttons are working...

Code for Activate De-Activate Switch :

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Simple Activate / De-Activate switch using Simple Css </title>
<style>
.switch {
position: relative;
display: inline-block;
width: 75px;
height: 34px;
}

.switch input {display:none;}

.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: red;
-webkit-transition: .4s;
transition: .4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}

input:checked + .slider {
background-color: green;
}

input:focus + .slider {
box-shadow: 0 0 1px green;
}

input:checked + .slider:before {
-webkit-transform: translateX(40px);
-ms-transform: translateX(40px);
transform: translateX(40px);
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}
</style>
</head>
<body>
<h2>Toggle Switch using simple css</h2>
<label class="switch">
<input type="checkbox" checked>
<span class="slider round"></span>
</label>
<label class="switch">
<input type="checkbox" >
<span class="slider round"></span>
</label>
</body>
</html> 

Post a Comment

0 Comments