Material CSS Switch

Developer
Size
2,979 Kb
Views
32,384

How do I make an material css switch?

Google Material inspired CSS checkbox switch.. What is a material css switch? How do you make a material css switch? This script and codes were developed by Travis Arnold on 12 September 2022, Monday.

Material CSS Switch Previews

Material CSS Switch - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Material CSS Switch</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ .switch { display: inline-block; width: 40px; height: 20px; padding: 4px; border-radius: 20px; background: #ccc; vertical-align: middle; position: relative; cursor: pointer; user-select: none; transition: background 350ms ease;
}
.switch:before, .switch:after { content: ""; display: block; width: 20px; height: 20px; border-radius: 50%; position: absolute; top: 50%; transition: all 350ms cubic-bezier(0, 0.95, 0.38, 0.98), background 150ms ease;
}
.switch:before { background: rgba(128, 128, 128, 0.075); transform: translate3d(0, -50%, 0) scale(0);
}
.switch:after { background: grey; transform: translate3d(0, -50%, 0);
}
.switch:active:before { transform: translate3d(0, -50%, 0) scale(3);
}
input:checked + .switch { background: #d0efa8;
}
input:checked + .switch:before { background: rgba(131, 177, 84, 0.075); transform: translate3d(100%, -50%, 0) scale(1);
}
input:checked + .switch:after { background: #83b154; transform: translate3d(100%, -50%, 0);
}
input:checked + .switch:active:before { background: rgba(131, 177, 84, 0.075); transform: translate3d(100%, -50%, 0) scale(3);
}
.center-xy { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="center-xy"> <input id="switch" type="checkbox" hidden /> <label for="switch" class="switch"></label>
</div>
</body>
</html>

Material CSS Switch - Script Codes CSS Codes

.switch { display: inline-block; width: 40px; height: 20px; padding: 4px; border-radius: 20px; background: #ccc; vertical-align: middle; position: relative; cursor: pointer; user-select: none; transition: background 350ms ease;
}
.switch:before, .switch:after { content: ""; display: block; width: 20px; height: 20px; border-radius: 50%; position: absolute; top: 50%; transition: all 350ms cubic-bezier(0, 0.95, 0.38, 0.98), background 150ms ease;
}
.switch:before { background: rgba(128, 128, 128, 0.075); transform: translate3d(0, -50%, 0) scale(0);
}
.switch:after { background: grey; transform: translate3d(0, -50%, 0);
}
.switch:active:before { transform: translate3d(0, -50%, 0) scale(3);
}
input:checked + .switch { background: #d0efa8;
}
input:checked + .switch:before { background: rgba(131, 177, 84, 0.075); transform: translate3d(100%, -50%, 0) scale(1);
}
input:checked + .switch:after { background: #83b154; transform: translate3d(100%, -50%, 0);
}
input:checked + .switch:active:before { background: rgba(131, 177, 84, 0.075); transform: translate3d(100%, -50%, 0) scale(3);
}
.center-xy { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
}
Material CSS Switch - Script Codes
Material CSS Switch - Script Codes
Home Page Home
Developer Travis Arnold
Username souporserious
Uploaded September 12, 2022
Rating 3.5
Size 2,979 Kb
Views 32,384
Do you need developer help for Material CSS Switch?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Travis Arnold (souporserious) Script Codes
Create amazing blog posts with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!