From eb02b8dbbf2364f0fd8f61400bc5ef011a3b89f2 Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Sat, 23 Dec 2023 23:37:08 +0800 Subject: [PATCH] feat: add dark mode --- quote_generator/index.html | 17 ++++++++++++----- quote_generator/script.js | 7 +++++++ quote_generator/styles.css | 34 ++++++++++++++++++++++++++-------- 3 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 quote_generator/script.js diff --git a/quote_generator/index.html b/quote_generator/index.html index 8928919..53e634f 100644 --- a/quote_generator/index.html +++ b/quote_generator/index.html @@ -5,6 +5,10 @@ Moon's Project + + + + @@ -15,12 +19,15 @@

- +
+ +
+
- - - - + + + + diff --git a/quote_generator/script.js b/quote_generator/script.js new file mode 100644 index 0000000..1163ae0 --- /dev/null +++ b/quote_generator/script.js @@ -0,0 +1,7 @@ +let darkModeIcon = document.querySelector('#dark-mode-icon'); + +darkModeIcon.onclick = () => { + darkModeIcon.classList.toggle('bx-sun'); + document.body.classList.toggle('dark-mode'); +}; + \ No newline at end of file diff --git a/quote_generator/styles.css b/quote_generator/styles.css index 2559cbf..06b92a2 100644 --- a/quote_generator/styles.css +++ b/quote_generator/styles.css @@ -1,3 +1,18 @@ +:root { + --button-color: #9DC4FF; + --button-hover-color: #5ca8f3; + --bg-color: #ffffffd7; + --text-color: #000000; +} + +.dark-mode { + --button-color: #66a1fa; + --button-hover-color: #8ec1f4; + --bg-color: #1b1919d7; + --dark-mode-icon-color: #ffffff; + --text-color: #ffffff; +} + html { background: #282828; height: 100%; @@ -21,12 +36,6 @@ body { z-index: 0; } -:root { - --button-color: #9DC4FF; - --button-hover-color: #5ca8f3; - --white: #FFFFFF; -} - .container { position: absolute; z-index: 1; @@ -38,7 +47,8 @@ body { margin: 0 auto; text-align: center; padding: 70px; - background-color: var(--white); + color: var(--text-color); + background-color: var(--bg-color); border-radius: 30px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); } @@ -49,7 +59,7 @@ body { button { background-color: var(--button-color); - color: var(--white); + color: var(--bg-color); font-size: 16px; border: none; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4); @@ -62,3 +72,11 @@ button { button:hover { background-color: var(--button-hover-color); } + +#dark-mode-icon { + margin-top: 15px; + font-size: 2.4rem; + color: var(--dark-mode-icon-color); + cursor: pointer; + opacity: 85%; +} \ No newline at end of file