Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark Mode Toggle Button improved #539

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
58 changes: 56 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,45 @@
<li><a href="#others">Others</a></li>

<li class="login"><a href="login/login.html">Login</a></li>
<li><label class="switch">
<!-- <li><label class="switch">
<input type="checkbox" id="theme-toggle" onchange="toggleTheme()">
<span class="slider"></span>
</label></li>
-->

<!--Dark and Light Mode Toggle Button-->
<li>
<input type="checkbox" id="theme-toggle" onchange="toggleTheme()" />
<label for="theme-toggle">
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg class="sun" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">

<g id="SVGRepo_bgCarrier" stroke-width="0" />

<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" />

<g id="SVGRepo_iconCarrier">
<circle cx="12" cy="12" r="6" stroke="#000000" stroke-width="1.5" />
<path d="M12 2V3" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M12 21V22" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M22 12L21 12" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M3 12L2 12" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M19.0708 4.92969L18.678 5.32252" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M5.32178 18.6777L4.92894 19.0706" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M19.0708 19.0703L18.678 18.6775" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
<path d="M5.32178 5.32227L4.92894 4.92943" stroke="#000000" stroke-width="1.5" stroke-linecap="round" />
</g>

</svg>
<?xml version="1.0" encoding="utf-8"?>
<svg class="moon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M3.32031 11.6835C3.32031 16.6541 7.34975 20.6835 12.3203 20.6835C16.1075 20.6835 19.3483 18.3443 20.6768 15.032C19.6402 15.4486 18.5059 15.6834 17.3203 15.6834C12.3497 15.6834 8.32031 11.654 8.32031 6.68342C8.32031 5.50338 8.55165 4.36259 8.96453 3.32996C5.65605 4.66028 3.32031 7.89912 3.32031 11.6835Z"
stroke="#000000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</label>
</li>

<!-- Inside the navbar ul -->
<a href="#" class="cart-button">
<img src="images/cart.png" alt="Cart Icon">
Expand Down Expand Up @@ -759,9 +794,28 @@ <h2>Feedback Form</h2>
<div class="gtranslate_wrapper"></div>
<script>window.gtranslateSettings = { "default_language": "en", "detect_browser_language": true, "wrapper_selector": ".gtranslate_wrapper" }</script>
<script src="https://cdn.gtranslate.net/widgets/latest/float.js" defer></script>
<script>
function toggleTheme() {
const body = document.body;
body.classList.toggle('dark-mode');
if (body.classList.contains('dark-mode')) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
}

window.onload = function () {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
document.getElementById('theme-toggle').checked = true;
}
}
</script>


</body>


</html>
</html>
90 changes: 89 additions & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,94 @@ html::-webkit-scrollbar-thumb:window-inactive {
background: rgb(156, 156, 156);
}

/*dark and light mode toggle button*/
label {
width: 75px;
height: 30px;
position: relative;
display: block;
background: #ebebeb;
border-radius: 30px;
box-shadow: inset 0px 3.75px 11.25px rgba(0, 0, 0, 0.4), inset 0px -3.75px 11.25px rgba(255, 255, 255, 0.4);
cursor: pointer;
transform: 0.3s;
border: 1px solid rgba(0, 0, 0, 0.2);
margin: 0 auto; /* Center align the toggle switch */
}

label:after {
content: "";
width: 27px;
height: 27px;
position: absolute;
top: 1.5px;
left: 2.25px;
background: linear-gradient(180deg, #ffcc89, #d88606);
border-radius: 135px;
box-shadow: 0px 3.75px 7.5px rgba(0, 0, 0, 0.2);
transform: 0.3s;
}

input {
width: 0;
height: 0;
visibility: hidden;
}

input:checked+label {
background: #d3d3d3;
}

input:checked+label:after {
left: 73px;
transform: translateX(-100%);
background: linear-gradient(180deg, #777, #3a3a3a);
}

label:active:after {
width: 37.5px;
}

.background {
width: 100vw;
height: 100vh;
background: #fff;
z-index: -1;
position: absolute;
transition: 0.3s;
}

input:checked+label+.background {
background: #242424;
}

label svg {
position: absolute;
width: 22.5px;
top: 3.75px;
z-index: 100;
}

label svg.sun {
left: 3.75px;
fill: #fff;
transition: 0.3s;
}

label svg.moon {
left: 48.75px;
fill: #7e7e7e;
transition: 0.3s;
}

input:checked+label svg.sun {
fill: #7e7e7e;
}

input:checked+label svg.moon {
fill: #fff;
}

.card {
width: 50%; /* Set a specific width */
margin: 10px auto; /* Center horizontally with automatic margins */
Expand Down Expand Up @@ -137,7 +225,7 @@ html::-webkit-scrollbar-thumb:window-inactive {

label {
display: block;
margin-bottom: 10px;
margin-bottom: 15px;
}

input,
Expand Down