Created
February 19, 2022 13:00
-
-
Save HeNy007/f6fe7f322dce010b9e8d0eed8bab08db to your computer and use it in GitHub Desktop.
Night Mode Switch toggle button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0/css/all.min.css" integrity="sha256-ybRkN9dBjhcS2qrW1z+hfCxq+1aBdwyQM5wlQoQVt/0=" crossorigin="anonymous" /> | |
<link rel="stylesheet" href="style.css"> | |
<title>Night Mode</title> | |
</head> | |
<body> | |
<div class="container night-mode-available"> | |
<div class="night-mode-button"> | |
<input type="checkbox" class="checkbox" id="night-mode"> | |
<label for="night-mode" class="label"> | |
<i class="fas fa-moon"></i> | |
<i class="fas fa-sun"></i> | |
<div class="blob"></div> | |
</label> | |
</div> | |
<div class="info night-mode-available"> | |
<h1>Hello World</h1> | |
</div> | |
</div> | |
<script type="text/javascript"> | |
document.querySelector('.checkbox').addEventListener('change',()=>{ | |
document.querySelectorAll('.night-mode-available').forEach(ele=>{ | |
ele.classList.toggle('night'); | |
}) | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
padding: 0; | |
margin: 0; | |
box-sizing: border-box; | |
} | |
.container { | |
height: 100vh; | |
width: 100%; | |
display: flex; | |
flex-direction: column; | |
justify-content: center; | |
align-items: center; | |
} | |
.container.night { | |
background-color: rgba(17, 16, 34, 0.911); | |
} | |
.label { | |
background-color: black; | |
display: flex; | |
height: 30px; | |
border-radius: 50px; | |
width: 100px; | |
justify-content: space-between; | |
align-items: center; | |
position: relative; | |
padding: 0 15px; | |
transition: all .5s ease-in-out; | |
cursor: pointer; | |
border: 2px solid black; | |
} | |
.label .fa-moon { | |
color: rgb(250, 250, 250); | |
} | |
label .fa-sun { | |
color: rgb(243, 188, 36); | |
} | |
.blob { | |
position: absolute; | |
left: 50%; | |
width: 50%; | |
height: 100%; | |
background: rgb(169, 241, 243); | |
border-radius: 50px; | |
transition: .5s ease all; | |
} | |
.checkbox { | |
opacity: 0; | |
position: absolute; | |
} | |
.info { | |
display: block; | |
margin-top: 50px; | |
} | |
.info.night { | |
color: white; | |
} | |
.checkbox:checked + .label .blob { | |
left: 0; | |
} | |
.checkbox:checked + .label { | |
background-color: rgb(82, 81, 83); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment