Professional Documents
Culture Documents
Calculator Code
Calculator Code
Calculator Code
<html>
<head>
<title>Calculator</title>
</head>
<body>
</body>
</html>
margin: 0;
padding: 0;
box-sizing: border-box;
HTML
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<div class=”container”>
</div>
</body>
</html>
CSS
.container{
width: 100%;
height: 100%;
background: purple;
HTML
<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<div class=”container”>
<div class=”calculator”>
<form>
<div>
<input type=”text” name=”display”>
</div>
<div>
<input type=”button” value=”AC”>
<input type=”button” value=”DEL”>
Calculator first row
<input type=”button” value=”.”>
<input type=”button” value=”/”>
</div>
</form>
</div>
</div>
</body>
</html>
Move everything to the center
CSS
.container{
width: 100%;
height: 100vh;
background: purple;
display: flex;
align-items: center;
justify-content: center;
}
.calculator{
Background: brown;
Padding: 20px;
Border-radius: 10px;
}
<html>
<head>
<title>Calculator</title>
</head>
<body>
<div class=”container”>
<div class=”calculator”>
<form>
<div>
<input type=”text” name=”display”>
</div>
<div>
<input type=”button” value=”AC”>
<input type=”button” value=”DEL”>
<input type=”button” value=”.”>
<input type=”button” value=”/”>
</div>
<div>
<input type=”button” value=”1”>
<input type=”button” value=”2”>
<input type=”button” value=”3”>
<input type=”button” value=”*”>
</div>
<div>
<input type=”button” value=”4”>
<input type=”button” value=”5”>
<input type=”button” value=”6”>
<input type=”button” value=”-”>
</div>
<div>
<input type=”button” value=”7”>
<input type=”button” value=”8”>
<input type=”button” value=”9”>
<input type=”button” value=”+”>
</div>
<div>
<input type=”button” value=”00”>
<input type=”button” value=”0”>
<input type=”button” value=”=”>
</div>
</form>
</div>
</div>
</body>
</html>
Add Calculator display button
CSS Inside the calculator, we have the form and the input file
border: 0;
outline: 0;
width: 60px;
height: 60px;
border-radius: 10px;
or
box-shadow: -8px -8px 15px rgba(255, 255, 255, 0.1), 5px 5px 15px rgba(0, 0, 0, 0.2);
background: transparent;
font-size: 20px;
color: white;
cursor: pointer;
margin: 10px
form .display{
display: flex;
justify-content: flex-end;
margin: 20px 0;
text-align: right;
flex: 1;
font-size: 45px;
box-shadow: none;
Edit the equal button to fit the space by adding a div class name as equal
<input type=”button” value=”=” class=”equal”>
</div>
Back to CSS
Form input.equal{
Width: 145px; double other widths
}
<div>
<input type=”button” value=”1” onclick=”display.value = ‘1’ “>
<input type=”button” value=”2” onclick=”display.value += ‘2’ “>
<input type=”button” value=”3” onclick=”display.value += ‘3’ “>
<input type=”button” value=”*” onclick=”display.value += ‘*’ “>
</div>
<div>
<input type=”button” value=”4” onclick=”display.value += ‘4’ “>
<input type=”button” value=”5” onclick=”display.value += ‘5’ “>
<input type=”button” value=”6” onclick=”display.value += ‘6’ “>
<input type=”button” value=”-” onclick=”display.value += ‘-’ “>
</div>
<div>
<input type=”button” value=”7” onclick=”display.value += ‘7’ “>
<input type=”button” value=”8” onclick=”display.value += ‘8’ “>
<input type=”button” value=”9” onclick=”display.value += ‘9’ “>
<input type=”button” value=”+” onclick=”display.value += ‘+’ “>
</div>
<div>
<input type=”button” value=”00” onclick=”display.value += ‘00’ “>
<input type=”button” value=”0” onclick=”display.value += ‘0’ “>
<input type=”button” value=”=”>
</div>
Add click functions to top buttons
For delete the command is different because it delete only one number