File tree Expand file tree Collapse file tree 3 files changed +70
-0
lines changed Expand file tree Collapse file tree 3 files changed +70
-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+ < title > Random Color Generator</ title >
6+ < link rel ="stylesheet " href ="styles.css ">
7+ </ head >
8+ < body >
9+ < div class ="container ">
10+ < div id ="colorCode "> #FFFFFF</ div >
11+ < button id ="btn "> Generate Color</ button >
12+ </ div >
13+
14+ < script src ="script.js "> </ script >
15+ </ body >
16+ </ html >
Original file line number Diff line number Diff line change 1+ const colorCode = document . getElementById ( 'colorCode' ) ;
2+ const btn = document . getElementById ( 'btn' ) ;
3+
4+ function getRandomColor ( ) {
5+ const hex = Math . floor ( Math . random ( ) * 0xffffff )
6+ . toString ( 16 )
7+ . padStart ( 6 , '0' ) ;
8+ return `#${ hex } ` ;
9+ }
10+
11+ function setColor ( ) {
12+ const color = getRandomColor ( ) ;
13+ document . body . style . backgroundColor = color ;
14+ colorCode . textContent = color ;
15+ }
16+
17+ btn . addEventListener ( 'click' , setColor ) ;
18+ window . addEventListener ( 'load' , setColor ) ;
Original file line number Diff line number Diff line change 1+ * {
2+ box-sizing : border-box;
3+ }
4+ body , html {
5+ margin : 0 ;
6+ height : 100% ;
7+ display : flex;
8+ justify-content : center;
9+ align-items : center;
10+ font-family : sans-serif;
11+ background-color : # ffffff ;
12+ }
13+ .container {
14+ text-align : center;
15+ padding : 2rem ;
16+ border : 2px solid # ccc ;
17+ border-radius : 12px ;
18+ background-color : white;
19+ }
20+ # colorCode {
21+ font-size : 2rem ;
22+ margin-bottom : 1rem ;
23+ font-weight : bold;
24+ }
25+ # btn {
26+ padding : 10px 20px ;
27+ font-size : 1rem ;
28+ border : none;
29+ background-color : # 0077ff ;
30+ color : white;
31+ border-radius : 6px ;
32+ cursor : pointer;
33+ }
34+ # btn : hover {
35+ background-color : # 005fcc ;
36+ }
You can’t perform that action at this time.
0 commit comments