Bulb On - Off

 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


*{
    padding0px;
    margin0px;
    box-sizingborder-box;
}

.container{
    
    displayflex;
    justify-contentcenter;
    Flex-direction : column;
    marginauto;
    align-itemscenter;
    min-height100vh;
    background-colorgrey;
}
.box{
    displayflex;   
    Flex-direction : column
    
}

#btn1 , #btn2{
    displayflex;
    Flex-direction : row
    
        margin30px;
    padding20px;
    background-colorrgb(787822);
    colorwhite;
}

#myImage{    
        widthauto;
        height100%;
        max-height20vh
}

0 Comments