Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ main{
margin-right: auto;
}

#change-theme{
/* #change-theme{
padding: 10px 15px;
border-radius: 50px;
background-color: var(--orange);
Expand All @@ -87,4 +87,41 @@ main{
}
#change-theme:hover{
background-color: transparent;
}
} */

.checkbox {
opacity: 0;
position: absolute;
}

.checkbox-label {
background-color: #111;
width: 50px;
height: 26px;
border-radius: 50px;
position: relative;
padding: 5px;
cursor: pointer;
display: flex;
justify-content: space-between;
align-items: center;
}

.fa-moon {color: #f1c40f;}

.fa-sun {color: #f39c12;}

.checkbox-label .ball {
background-color: #fff;
width: 22px;
height: 22px;
position: absolute;
left: 2px;
top: 2px;
border-radius: 50%;
transition: transform 0.2s linear;
}

.checkbox:checked + .checkbox-label .ball {
transform: translateX(24px);
}
8 changes: 7 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
</a>
</div>
<div class="theme-toggle">
<button id="change-theme">Toggle theme</button>
<!-- <button id="change-theme">Toggle theme</button> -->
<input type="checkbox" class="checkbox" id="checkbox">
<label for="checkbox" class="checkbox-label">
<i class="fas fa-moon"></i>
<i class="fas fa-sun"></i>
<span class="ball"></span>
</label>
</div>

<div class="nav-links">
Expand Down
13 changes: 9 additions & 4 deletions js/toggle-theme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
var theme=document.getElementById("change-theme");
theme.onclick=function(){
document.body.classList.toggle("light-theme");
}
// var theme=document.getElementById("change-theme");
// theme.onclick=function(){
// document.body.classList.toggle("light-theme");
// }

const checkbox = document.getElementById("checkbox")
checkbox.addEventListener("change", () => {
document.body.classList.toggle("light-theme")
})