diff --git a/CSS/style.css b/CSS/style.css index 76d54c2..d253256 100644 --- a/CSS/style.css +++ b/CSS/style.css @@ -127,7 +127,7 @@ footer { margin: auto; } .info-box { - height: 480px !important; + min-height: 480px !important; } .card { box-shadow: rgba(0, 0, 0, 0.2) 0px 20px 50px -12px; diff --git a/CSS/theme.css b/CSS/theme.css new file mode 100644 index 0000000..29bd0b8 --- /dev/null +++ b/CSS/theme.css @@ -0,0 +1,35 @@ +:root { + --grid-unit: 1rem; + --border-radius-base: 0.5rem; +} + +[data-theme='light'] { + --color-bg: #ffffff; + --color-fg: #000000; +} + +[data-theme='dark'] { + --color-bg: #100909e0; + --color-fg: #ffffff; +} + +/* example use of CSS custom properties */ +body { + background-color: var(--color-bg); + color: var(--color-fg); +} +.light-theme { + background-color: var(--color-bg-light); + color: var(--color-fg-light); +} +.dark-theme { + background-color: var(--color-bg-dark); + color: var(--color-fg-dark); +} +.bg-off-white { + background-color: var(--color-bg); + color: var(--color-fg); +} +.nav-link { + color: #404146; +} diff --git a/JS/theme.js b/JS/theme.js new file mode 100644 index 0000000..9e03a76 --- /dev/null +++ b/JS/theme.js @@ -0,0 +1,56 @@ +const localStorageTheme = localStorage.getItem('theme'); +const systemSettingDark = window.matchMedia('(prefers-color-scheme: dark)'); +function calculateSettingAsThemeString({ + localStorageTheme, + systemSettingDark, +}) { + if (localStorageTheme !== null) { + return localStorageTheme; + } + if (systemSettingDark.matches) { + return 'dark'; + } + return 'light'; +} +let currentThemeSetting = calculateSettingAsThemeString({ + localStorageTheme, + systemSettingDark, +}); +// target the button using the data attribute we added earlier +const button = document.querySelector('[data-theme-toggle]'); +button.addEventListener('click', () => { + const newTheme = currentThemeSetting === 'dark' ? 'light' : 'dark'; + // update the button text + const newCta = + newTheme === 'dark' ? 'Change to light theme' : 'Change to dark theme'; + button.innerText = newCta; + // use an aria-label if you are omitting text on the button + // and using sun/moon icons, for example + button.setAttribute('aria-label', newCta); + // update theme attribute on HTML to switch theme in CSS + document.querySelector('html').setAttribute('data-theme', newTheme); + // update in local storage + localStorage.setItem('theme', newTheme); + // update the currentThemeSetting in memory + currentThemeSetting = newTheme; +}); +function applyTheme(theme) { + document.documentElement.setAttribute('data-theme', theme); + const heroSection = document.querySelector('.bg-off-white'); + heroSection.classList.remove('.light-theme', '.dark-theme'); + heroSection.classList.add(`${theme}-theme`); + + const heroText = document.querySelector('.heroText'); + heroText.classList.remove('light-theme', 'dark-theme'); + heroText.classList.add(`${theme}-theme`); + + const navText = document.querySelector('.nav-item'); + navText.classList.remove('light-theme', 'dark-theme'); + navText.classList.add(`${theme}-theme`); + + const footerText = document.querySelector('.copyright'); + footerText.classList.remove('light-theme', 'dark-theme'); + footerText.classList.add(`${theme}-theme`); +} +// Apply the theme when the page loads +applyTheme(localStorageTheme); diff --git a/about.html b/about.html index 440dc76..8fa1b83 100644 --- a/about.html +++ b/about.html @@ -26,10 +26,7 @@
- - -