index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="light.css">
<title>Light on off </title>
</head>
<body>
<div class= "container">
<div class="box" id="box">
<h1 id = "h1"> </h1>
<img src="image/bulb-off.png" alt=" no picutre" id="myImage">
<button class = "btn" onclick ="bulbOn()" id="btn1">On</button>
<button class = "btn" onclick ="bulbOff()" id="btn2">Off</button>
</div>
</div>
<script src="light.js"></script>
</body>
</html>
index,js
function bulbOn() {
document.getElementById("h1").innerHTML = "LIGHT ON"
document.getElementById("myImage").height = '200px'
document.getElementById("myImage").width = '200px'
document.getElementById("myImage").src = 'image/bulb-on.png'
}
function bulbOff() {
document.getElementById("h1").innerHTML = "LIGHT OFF"
document.getElementById("myImage").height = '200px'
document.getElementById("myImage").width = '200px'
document.getElementById("myImage").src = 'image/bulb-off.png'
}
index.css
*{
padding: 0px;
margin: 0px;
box-sizing: border-box;
}
.container{
display: flex;
justify-content: center;
Flex-direction : column;
margin: auto;
align-items: center;
min-height: 100vh;
background-color: grey;
}
.box{
display: flex;
Flex-direction : column;
}
#btn1 , #btn2{
display: flex;
Flex-direction : row;
margin: 30px;
padding: 20px;
background-color: rgb(78, 78, 22);
color: white;
}
#myImage{
width: auto;
height: 100%;
max-height: 20vh;
}
0 Comments