Sunday 6 March 2022

how to create calculator in html and css

 


 html Code:

<!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">
<script src="d.js"></script>
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="container">
<form class="form">
<div class="display">
<input type="text" placeholder="0" name="displayResult" id="dis" disabled/>
</div>
<div class="button">
<div class="row">
<input type="button" value="C" onclick="clearScreen()">
<input type="button" value="+/-" onclick="Screen('+')">
<input type="button" value="X" id="ns">
<input type="button" value="%" id="bill" onclick="Screen('%')">
</div>
<div class="row">
<input type="button" value="7" onclick="Screen('7')">
<input type="button" value="8" onclick="Screen('8')">
<input type="button" value="9" onclick="Screen('9')">
<input type="button" value="X" id="bill" onclick="Screen('*')">
</div>
<div class="row">
<input type="button" value="4" onclick="Screen('4')">
<input type="button" value="5" onclick="Screen('5')">
<input type="button" value="6" onclick="Screen('6')">
<input type="button" value="-" id="bill" onclick="Screen('-')">
</div>
<div class="row">
<input type="button" value="1" onclick="Screen('1')">
<input type="button" value="2" onclick="Screen('2')">
<input type="button" value="3" onclick="Screen('3')">
<input type="button" value="+" id="bill" onclick="Screen('+')">
</div>
<div class="row">
<input type="button" value="0" id="ze" onclick="Screen('0')">
<input type="button" value="." onclick="Screen('.')">
<input type="button" value="=" id="bill" onclick="calculate()">
</div>

</div>
</form>
</div>
</body>
</html>

 Css Code:


*{
margin: 0;
padding: 0;
}

body{
background-color: rgb(41, 36, 36);
padding: 0;
margin: 0;
}

.container{
width: 400px;
height: 454px;
background-color: rgb(231, 231, 231);
border-radius: 10px;
position: fixed;
left: 30em;
top: 5em
}
#dis{
width: 386px;
height: 100px;
text-align: right;
text-decoration: none;
border: none;
padding-right: 12px;
background-color: rgb(231, 231, 231);
color:gray;
font-size: xx-large;
font-weight: bolder;
border-top-left-radius: 9px;
border-top-right-radius: 9px;
}
.row{
margin: 0;
padding-left: 0px;
}
input[type=button]{
width: 96.1px;
height: 64px;
white-space: 0;
border: none;
font-size: 25px;
background-color: rgb(231, 231, 231);
}
input[type=button]:hover{
background-color: rgb(192, 185, 185);
}
#bill{
background-color: rgb(248, 155, 6);
color: wheat;
}
#bill:hover{
background-color: rgb(160, 104, 14);
color: #fff;
}
#ze{
width: 197.5px;
}
 

 

 

JavScript:


function Screen(value){
document.getElementById('dis').value+=value;
}
function calculate(){
var p=document.getElementById('dis').value;
var q=eval(p);
document.getElementById("dis").value = q;
}
function clearScreen() {
document.getElementById("dis").value = "";
}

No comments:

Post a Comment

How to install and setup java in Windows

 Step 1:          first, you want to ensure that the JDK is installed in your system                        Then press Windows +  R  key  as...