File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
7+ < title > DarkMode</ title >
8+ < link rel ="stylesheet " href ="style.css " />
9+ < link rel ="stylesheet " href ="mediaqueries.css " />
10+ </ head >
11+ < body >
12+ < div class ="container ">
13+ < button id ="mode-toggle "> Dark Mode</ button >
14+ </ div >
15+ </ footer >
16+ < script src ="script.js "> </ script >
17+ </ body >
18+ </ html >
Original file line number Diff line number Diff line change 1+ const modeToggle = document . getElementById ( 'mode-toggle' ) ;
2+ const body = document . body ;
3+
4+ modeToggle . addEventListener ( 'click' , ( ) => {
5+ body . classList . toggle ( 'dark-mode' ) ;
6+
7+ if ( body . classList . contains ( 'dark-mode' ) ) {
8+ modeToggle . textContent = 'Switch to Light Mode' ;
9+ } else {
10+ modeToggle . textContent = 'Switch to Dark Mode' ;
11+ }
12+ } ) ;
Original file line number Diff line number Diff line change 1+
2+ : root {
3+ --background-color : white;
4+ --text-color : black;
5+ }
6+
7+ body {
8+ background-color : var (--background-color );
9+ color : var (--text-color );
10+ transition : background-color 0.3s , color 0.3s ;
11+ }
12+
13+ .dark-mode {
14+ --background-color : black;
15+ --text-color : white;
16+ }
17+
18+ .container {
19+ max-width : 800px ;
20+ margin : 0 auto;
21+ padding : 20px ;
22+ }
23+
24+ # mode-toggle {
25+ padding : 10px 20px ;
26+ cursor : pointer;
27+ }
28+
You can’t perform that action at this time.
0 commit comments