how to add calculator in html and css

Solutions on MaxInterview for how to add calculator in html and css by the best coders in the world

showing results for - "how to add calculator in html and css"
Adel
31 Nov 2020
1<!DOCTYPE html>
2<html>
3<head>
4<title>HTML and CSS Calculator</title>
5 <link rel="stylesheet" href="style.css">
6<link href='https://fonts.googleapis.com/css?family=Orbitron' rel='stylesheet' type='text/css'>
7<style>
8body {
9      background-color: #262626;
10      }
11.container {
12      top:50%;
13      left:50%;
14      position:absolute;
15      transform:translate(-50%,-50%);
16      width: 250px;
17      padding: 8px 8px 20px 8px;
18      margin: 20px auto;
19      background-color: #ABABAB;
20      border-radius: 4px;
21      border-top: 2px solid #FFF;
22      border-right: 2px solid #FFF;
23      border-bottom: 2px solid #C1C1C1;
24      border-left: 2px solid #C1C1C1;
25      box-shadow: -3px 3px 7px rgba(0, 0, 0, .6);
26}
27#display {
28      display: block;
29      margin: 15px auto;
30      height: 50px;
31      width: 250px;
32      padding: 0 10px;
33      border-radius: 4px;
34      border-top: 2px solid #C1C1C1;
35      border-right: 2px solid #C1C1C1;
36      border-bottom: 2px solid #FFF;
37      border-left: 2px solid #FFF;
38      background-color: #FFF;
39      box-shadow: inset 0px 0px 10px #030303;
40      font-size: 28px;
41      color: #000;
42      text-align: right;
43      font-weight:bold;
44      font-family: Orbitron;
45}
46.button {
47      display: inline-block;
48      margin: 3px;
49      width: 60px;
50      height: 60px;
51      font-size: 25px;
52      font-weight: bold;
53      border-radius: 4px;
54      box-sizing:border-box;
55      font-family: Orbitron;
56}
57.mathButtons {
58      margin: 2px 2px 6px 2px;
59      color: #FFF;
60      text-shadow: -1px -1px 0px #44006F;
61      background-color: #434343;
62      border-top: 2px solid #C1C1C1;
63      border-right: 2px solid #C1C1C1;
64      border-bottom: 2px solid #181818;
65      border-left: 2px solid #181818;
66      box-shadow: 0px 0px 2px #030303;
67}
68.digits {
69      color: #181818;
70      text-shadow: 1px 1px 0px #FFF;
71      background-color: #EBEBEB;
72      border-top: 2px solid #FFF;
73      border-right: 2px solid #FFF;
74      border-bottom: 2px solid #C1C1C1;
75      border-left: 2px solid #C1C1C1;
76      border-radius: 4px;
77      box-shadow: 0px 0px 2px #030303;
78}
79.digits:hover,
80.mathButtons:hover,
81#clearButton:hover {
82      background-color: #FFBA75;
83      box-shadow: 0px 0px 2px #FFBA75, inset 0px -20px 1px #FF8000;
84      border-top: 2px solid #FFF;
85      border-right: 2px solid #FFF;
86      border-bottom: 2px solid #AE5700;
87      border-left: 2px solid #AE5700;
88}
89 
90#clearButton {
91      color: #FFF;
92      text-shadow: -1px -1px 0px #44006F;
93      background-color: #D20000;
94      border-top: 2px solid #FF8484;
95      border-right: 2px solid #FF8484;
96      border-bottom: 2px solid #800000;
97      border-left: 2px solid #800000;
98      box-shadow: 0px 0px 2px #030303, inset 0px -20px 1px #B00000;
99}
100</style>
101</head>
102<body>
103<div class="wrap">
104      <fieldset class="container">
105            <form name="calculator">
106 
107                  <input id="display" type="text" name="display" readonly>
108 
109                  <input class="button digits" type="button" value="7" onclick="calculator.display.value += '7'">
110                  <input class="button digits" type="button" value="8" onclick="calculator.display.value += '8'">
111                  <input class="button digits" type="button" value="9" onclick="calculator.display.value += '9'">
112                  <input class="button mathButtons" type="button" value="+" onclick="calculator.display.value += ' + '">
113                  <br>
114                  <input class="button digits" type="button" value="4" onclick="calculator.display.value += '4'">
115                  <input class="button digits" type="button" value="5" onclick="calculator.display.value += '5'">
116                  <input class="button digits" type="button" value="6" onclick="calculator.display.value += '6'">
117                  <input class="button mathButtons" type="button" value="-" onclick="calculator.display.value += ' - '">
118                  <br>
119                  <input class="button digits" type="button" value="1" onclick="calculator.display.value += '1'">
120                  <input class="button digits" type="button" value="2" onclick="calculator.display.value += '2'">
121                  <input class="button digits" type="button" value="3" onclick="calculator.display.value += '3'">
122                  <input class="button mathButtons" type="button" value="x" onclick="calculator.display.value += ' * '">
123                  <br>
124                  <input id="clearButton" class="button" type="button" value="C" onclick="calculator.display.value = ''">
125                  <input class="button digits" type="button" value="0" onclick="calculator.display.value += '0'">
126                  <input class="button mathButtons" type="button" value="=" onclick="calculator.display.value = eval(calculator.display.value)">
127                  <input class="button mathButtons" type="button" value="/" onclick="calculator.display.value += ' / '">
128            </form>
129      </fieldset>
130</div>
131</body>
132</html>