im having some troubles to make a dark and light mode when i tried to switch my latters dont change and i really dont know why can you guys explain me why and how to make it work? heres my code im using flask u.u
CSS
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root{
--bs-dark: #212529;
--bs-light: #fff;
}
.theme-container {
width: 70px;
height: 70px;
border-radius: 50%;
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
justify-content: center;
align-items: center;
transition: 0.5s;
}
.theme-container:hover {
opacity: 0.8;
}
.shadow-dark {
background: linear-gradient(145deg, #23282c, #1e2125);
box-shadow: 17px 17px 23px #1a1d20,
-17px -17px 23px #282d32, inset 5px 5px 4px #1e2226,
inset -5px -5px 4px #24282c;
}
.shadow-light {
box-shadow: 7px 7px 15px -10px #bbcfda, -4px -4px 13px #ffffff,
inset 7px 7px 3px rgba(209, 217, 230, 0.35),
inset -11px -11px 3px rgba(255, 255, 255, 0.3)
}
@keyframes change {
0% {
transform: scale(1);
}
100% {
transform: scale(1.4);
}
}
.change {
animation-name: change;
animation-duration: 1s;
animation-direction: alternate;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
}
.formbold-mb-3 {
margin-bottom: 15px;
}
.formbold-img {
display: block;
margin: 0 auto;
display: flex;
}
.formbold-form-select {
margin: 0 auto;
background-color: #fff;
align-content: center;
}
.formbold-main-wrapper {
display: flex;
align-items: center;
justify-content: center;
padding: 48px;
}
.formbold-form-wrapper {
margin: 0 auto;
max-width: 570px;
width: 100%;
padding: 40px;
}
.formbold-img {
display: block;
margin: 0 auto 45px;
}
.formbold-input-wrapp > div {
display: flex;
gap: 20px;
}
.formbold-input-flex {
display: flex;
gap: 20px;
margin-bottom: 15px;
}
.formbold-input-flex > div {
width: 50%;
}
.formbold-form-input {
width: 100%;
padding: 13px 22px;
border-radius: 5px;
border: 1px solid #dde3ec;
background: #ffffff;
font-weight: 500;
font-size: 16px;
color: #536387;
outline: none;
resize: none;
}
.formbold-form-input::placeholder,
select.formbold-form-input,
.formbold-form-input[type='date']::-webkit-datetime-edit-text,
.formbold-form-input[type='date']::-webkit-datetime-edit-month-field,
.formbold-form-input[type='date']::-webkit-datetime-edit-day-field,
.formbold-form-input[type='date']::-webkit-datetime-edit-year-field {
color: rgba(83, 99, 135, 0.5);
}
.formbold-form-input:focus {
border-color: #747478;
box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.05);
}
.formbold-form-label {
font-weight: 500;
font-size: 14px;
line-height: 24px;
display: block;
margin-bottom: 10px;
color: var(--bs-light); /* texto negro por defecto */
}
.formbold-form-file-flex {
display: flex;
align-items: center;
gap: 20px;
}
.formbold-form-file-flex .formbold-form-label {
margin-bottom: 0;
}
.formbold-form-file {
font-size: 14px;
line-height: 24px;
color: #a2a2a2;
}
.formbold-form-file::-webkit-file-upload-button {
display: none;
}
.formbold-form-file:before {
content: 'Upload file';
display: inline-block;
background: #ffffff;
box-shadow: inset 0px 0px 2px rgba(193, 193, 193, 0.25);
border-radius: 10px;
padding: 2px 15px;
outline: none;
white-space: nowrap;
user-select: none;
cursor: pointer;
color: #464646;
font-weight: 500;
font-size: 13px;
line-height: 16px;
margin-right: 10px;
}
.formbold-btn {
text-align: center;
width: 100%;
font-size: 16px;
border-radius: 5px;
padding: 14px 25px;
border: none;
font-weight: 500;
background-color: #6a64f1;
color: white;
cursor: pointer;
margin-top: 25px;
}
.formbold-btn:hover {
box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.05);
}
.formbold-w-45 {
width: 45%;
}
javascript
document.body.style="background-color: var(--bs-dark);transition: 0.5s;"
const sun = "https://www.uplooder.net/img/image/55/7aa9993fc291bc170abea048589896cf/sun.svg";
const moon = "https://www.uplooder.net/img/image/2/addf703a24a12d030968858e0879b11e/moon.svg"
var theme = "dark";
const root = document.querySelector(":root");
const container = document.getElementsByClassName("theme-container")[0];
const themeIcon = document.getElementById("theme-icon");
container.addEventListener("click", setTheme);
function setTheme() {
switch (theme) {
case "dark":
setLight();
theme = "light";
break;
case "light":
setDark();
theme = "dark";
break;
}
}
function setLight() {
root.style.setProperty(
"--bs-dark",
"linear-gradient(318.32deg, #c3d1e4 0%, #dde7f3 55%, #d4e0ed 100%)"
);
container.classList.remove("shadow-dark");
setTimeout(() => {
container.classList.add("shadow-light");
themeIcon.classList.remove("change");
}, 300);
themeIcon.classList.add("change");
themeIcon.src = sun;
}
function setDark() {
root.style.setProperty("--bs-dark", "#212529");
container.classList.remove("shadow-light");
setTimeout(() => {
container.classList.add("shadow-dark");
themeIcon.classList.remove("change");
}, 300);
themeIcon.classList.add("change");
themeIcon.src = moon;
}
i really tried everything i know like add more const and even use chatgpt but nothing
const themeBtn = document.querySelector('.theme-container');
themeBtn.addEventListener('click', function() {
document.body.classList.toggle('light-mode');
});
and css properties
.theme-container.light-mode .formbold-form-input,
.theme-container.light-mode .formbold-form-label,
.theme-container.light-mode .formbold-form-file {
color: #212529;
}