Skip to content

CSS ON-OFF BUTTON

HTML CODE:

<!DOCTYPE html>
<html>
<head>
    <title>page</title>
     <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="1.page.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
</head>
<body>

    <div class="mid">
        <label class="rocker">
            <input type="checkbox">
            <span class="switch-left">ON</span>
            <span class="switch-right">OFF</span>
        </label>
    </div>

</body>
</html>

CSS CODE:

@import url('https://fonts.googleapis.com/css?family=Chakra+Petch:600');
body , html{
    padding: 0;
    background: #262626;
    font-family: 'Chakra Petch', sans-serif;
}
*,*:before,*after{
    box-sizing: inherit;
    margin:0;
    padding: 0;
}
.mid{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 85vh;
}
.rocker{
    display: inline-block;
    position: relative;
    font-size: 2em;
    font-weight: bold;
    text-align: center;
    color: #888;
    width: 7em;
    height: 4em;
    overflow: hidden;
    border-bottom: 0.5em solid #eee;
}
.rocker::before{
    content: "";
    position: absolute;
    top:1em;
    left: 0;
    right: 0;
    bottom: 0;
    background: #999;
    border: 0.5em solid #eee;
    border-bottom: 0;
}
.rocker input{
    -webkit-appearance:none;
    width: 0;
    height: 0;
}
.switch-left,
.switch-right{
    cursor: pointer;
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2.5em;
    width: 3em;
    transition: .2s;
}
.switch-left{
    height: 2.4em;
    width: 2.75em;
    left: 0.85em;
    bottom: 0.4em;
    background: #ddd;
    transform: rotate(15deg) skewX(15deg);
}
.switch-right{
    right: 0.5em;
    bottom: 0;
    background: #bd5757;
    color: #fff;
}
.switch-left::before,
.switch-right::before{
    content: "";
    position: absolute;
    width: 0.4em;
    height: 2.45em;
    bottom: -0.45em;
    background: #ccc;
    transform: skewY(-65deg);
}
.switch-left::before {
  left: -0.4em;
}
.switch-right::before {
  right: -0.375em;
  background-color: transparent;
  transform: skewY(65deg);
}
input:checked + .switch-left{
    background: #0084d0;
    color: #fff;
    bottom: 0px;
    left:0.5em;
    height: 2.5em;
    width: 3em;
    transform: rotate(0deg) skewX(0deg);
}
input:checked + .switch-left::before {
  background-color: transparent;
  width: 3.0833em;
}
input:checked + .switch-left + .switch-right {
  background-color: #ddd;
  color: #888;
  bottom: 0.4em;
  right: 0.8em;
  height: 2.4em;
  width: 2.75em;
  transform: rotate(-15deg) skewX(-15deg);
}
input:checked + .switch-left + .switch-right::before {
  background-color: #ccc;
}
input:focus + .switch-left {
  color: #333;
}
input:checked:focus + .switch-left {
  color: #fff;
}
input:focus + .switch-left + .switch-right {
  color: #fff;
}
input:checked:focus + .switch-left + .switch-right {
  color: #333;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: