While building a basic application, when I click a button, the text inside my currently focused input overflows only in Chrome. However, that text can be accessed using (right) arrow key(s). Is there any way to avoid this? I tried clipboard copy-paste but that did not work.
JavaScript
x
110
110
1
const peopleElem = document.querySelector("#people");
2
const billElem = document.querySelector("#bill");
3
const submit = document.querySelector("[type="submit"]");
4
const form = document.querySelector("form");
5
const tipPerPersonElem = document.querySelector("[data-tip-person]");
6
const totalPerPersonElem = document.querySelector("[data-total-person]");
7
let billError = peopleError = false;
8
9
class TipCalc {
10
constructor() {
11
this.tipPerPerson = 0;
12
this.totalPerPerson = 0;
13
this.tip = 0
14
this.tipPercent = 0;
15
this.bill = parseFloat(billElem.value);
16
this.people = parseFloat(peopleElem.value);
17
}
18
19
getTip() {
20
const element = document.querySelector(".active");
21
if (!element) return 0;
22
if (element.tagName === "BUTTON") return this.tipPercent = element.innerText.replace("%", "");
23
return this.tipPercent = element.value.replace("%", "");
24
}
25
26
getTipPerPerson() {
27
this.getTip();
28
this.tip = ((this.tipPercent / 100) * this.bill);
29
this.tipPerPerson = this.tip / this.people;
30
return this.tipPerPerson;
31
}
32
33
getTotalPerPerson() {
34
this.getTipPerPerson();
35
this.totalPerPerson = (this.bill + this.tip) / this.people
36
return this.totalPerPerson;
37
}
38
}
39
40
const tipOptions = [document.querySelectorAll("button"), document.querySelector("#custom")];
41
tipOptions.forEach(option => {
42
if (option.tagName === "INPUT" && option.value.length) option.addEventListener("keyup", () => {
43
tipOptions.forEach(option => option.classList.remove("active"));
44
option.classList.toggle("active");
45
})
46
if (!(option.type == "submit")) option.addEventListener("click", () => {
47
tipOptions.forEach(option => option.classList.remove("active"));
48
option.classList.toggle("active");
49
})
50
})
51
52
form.addEventListener("submit", event => {
53
event.preventDefault();
54
checkInputForError(peopleElem, peopleError, true);
55
checkInputForError(billElem, billError, false);
56
if (billError || peopleError) return;
57
const tipCalculator = new TipCalc();
58
const tip = isNaN(tipCalculator.getTipPerPerson()) ? 0 : tipCalculator.getTipPerPerson();
59
const total = isNaN(tipCalculator.getTotalPerPerson()) ? 0 : tipCalculator.getTotalPerPerson();
60
const formatter = new Intl.NumberFormat(undefined, {
61
style: "currency",
62
currency: "USD",
63
signDisplay: "never"
64
});
65
tipPerPersonElem.innerText = formatter.format(tip);
66
totalPerPersonElem.innerText = formatter.format(total);
67
submit.style.display = "none";
68
const resetBtn = document.querySelector("[type="reset"]");
69
resetBtn.style.display = "block";
70
resetBtn.addEventListener("click", () => {
71
reset()
72
resetBtn.style.display = "none";
73
submit.style.display = "block";
74
})
75
})
76
77
document.addEventListener("DOMContentLoaded", () => {
78
reset()
79
})
80
81
peopleElem.addEventListener("keyup", () => checkInputForError(peopleElem, peopleError, true));
82
billElem.addEventListener("keyup", () => checkInputForError(billElem, billError, false));
83
84
function checkInputForError(input, error, showError) {
85
const value = input.value.trim() || 0;
86
if (!value || isNaN(parseFloat(value)) || parseFloat(value) == 0) {
87
if (showError) document.querySelector(".warning").style.display = "inline";
88
input.classList.add("error");
89
error = true;
90
} else {
91
if (showError) document.querySelector(".warning").style.display = "none";
92
input.classList.remove("error");
93
input.classList.add("correct");
94
error = false;
95
}
96
}
97
98
function reset(submit = false) {
99
const tipPerPersonElem = document.querySelector("[data-tip-person]");
100
const totalPerPersonElem = document.querySelector("[data-total-person]");
101
tipPerPersonElem.innerText = "";
102
totalPerPersonElem.innerText = "";
103
console.log(tipPerPersonElem.innerText, totalPerPersonElem.innerText, "reset", submit);
104
tipOptions.forEach(option => option.classList.remove("active"));
105
document.querySelectorAll("input").forEach(input => {
106
input.classList.remove("correct");
107
input.classList.remove("error");
108
input.value = "";
109
})
110
}
JavaScript
1
345
345
1
:root {
2
--primary-color: hsl(172, 67%, 45%);
3
--very-dark-cyan: hsl(183, 100%, 15%);
4
--dark-grayish-cyan: hsl(186, 14%, 43%);
5
--grayish-cyan: hsl(184, 14%, 56%);
6
--light-grayish-cyan: hsl(185, 41%, 84%);
7
--very-light-grayish-cyan: hsl(189, 41%, 97%);
8
--white: hsl(0, 0%, 100%);
9
--primary-font-size: 24px;
10
--primary-font-family: 'Space Mono', monospace;
11
}
12
13
14
/* GLOABAL TAGS */
15
16
body {
17
width: 100%;
18
margin: 0;
19
overflow: hidden;
20
font-family: var(--primary-font-family);
21
background-color: var(--light-grayish-cyan);
22
}
23
24
header {
25
text-align: center;
26
}
27
28
h1 {
29
color: var(--very-dark-cyan);
30
margin-top: 0;
31
text-transform: uppercase;
32
}
33
34
h1 span {
35
display: block;
36
margin: 0;
37
}
38
39
label {
40
display: block;
41
text-transform: capitalize;
42
}
43
44
button {
45
outline: none;
46
border: none;
47
text-align: center;
48
background-color: var(--very-dark-cyan);
49
font-size: var(--primary-font-size);
50
color: var(--white);
51
text-transform: capitalize;
52
margin: 8px;
53
padding-top: 8px;
54
padding-bottom: 8px;
55
border-radius: 4px;
56
cursor: pointer;
57
}
58
59
legend {
60
margin-bottom: 8px;
61
}
62
63
64
/* Chrome,
65
Safari,
66
Edge, */
67
68
69
/* Opera */
70
71
input::-webkit-outer-spin-button,
72
input::-webkit-inner-spin-button {
73
-webkit-appearance: none;
74
margin: 0;
75
}
76
77
78
/* Firefox */
79
80
input[type=number] {
81
-moz-appearance: textfield;
82
}
83
84
input {
85
display: block;
86
border: none;
87
background-color: var(--very-light-grayish-cyan);
88
font-size: var(--primary-font-size);
89
height: 30px;
90
color: var(--very-dark-cyan);
91
background-repeat: no-repeat;
92
background-position: left center;
93
}
94
95
input:not(#custom) {
96
text-indent: 99.8%;
97
}
98
99
aside {
100
font-size: 11px;
101
text-align: center;
102
}
103
104
aside a {
105
color: hsl(228, 45%, 44%);
106
}
107
108
109
/* END OF GLOBAL TAGS GENERIC IDs */
110
111
#bill {
112
background-image: url('https://kaustubhmaladkar.github.io/Tip-Calculator/images/icon-dollar.svg');
113
}
114
115
#people {
116
background-image: url('https://kaustubhmaladkar.github.io/Tip-Calculator/images/icon-person.svg');
117
}
118
119
120
/* END OF GENERIC IDs GENERIC CLASSES*/
121
122
button,
123
#custom {
124
width: calc(50% - 20px);
125
font-weight: bold;
126
}
127
128
129
/* END OF GENERIC CLASSES */
130
131
132
/* INPUT */
133
134
.input {
135
background-color: var(--white);
136
color: var(--dark-grayish-cyan);
137
border-top-right-radius: 20px;
138
border-top-left-radius: 20px;
139
margin-top: 20px;
140
padding-bottom: 30px;
141
}
142
143
.input legend {
144
margin-top: 20px;
145
margin-left: 20px;
146
}
147
148
legend:nth-of-type(2) label {
149
width: 100%;
150
}
151
152
legend:nth-of-type(2) {
153
display: flex;
154
flex-wrap: wrap;
155
}
156
157
[for="people"] {
158
display: inline;
159
}
160
161
.warning {
162
display: none;
163
/* margin-left: 92px; */
164
color: red;
165
font-size: 12px;
166
background-color: transparent;
167
}
168
169
input#custom {
170
background-color: var(--white);
171
color: var(--dark-grayish-cyan);
172
margin-top: 12px;
173
margin-left: 2px;
174
padding-bottom: 8px;
175
opacity: 1;
176
}
177
178
input#custom::placeholder {
179
text-transform: capitalize;
180
color: var(--dark-grayish-cyan);
181
opacity: 1;
182
}
183
184
185
/* END OF INPUT */
186
187
188
/*OUTPUT*/
189
190
.output {
191
background-color: var(--very-dark-cyan);
192
display: flex;
193
margin-top: -8px;
194
justify-content: center;
195
align-items: center;
196
flex-direction: column;
197
border-radius: 10px;
198
}
199
200
.output div,
201
.output span {
202
width: 100%;
203
}
204
205
.output>div>div {
206
display: flex;
207
gap: 15px;
208
}
209
210
.output>div>div:first-of-type {
211
margin-top: 30px;
212
margin-bottom: 15px;
213
}
214
215
.output>div>div:last-of-type {
216
margin-top: 15px;
217
margin-bottom: 30px;
218
}
219
220
[type="submit"],
221
[type="reset"] {
222
font-family: var(--primary-font-family);
223
background-color: var(--primary-color);
224
width: 90%;
225
text-align: center;
226
color: var(--very-dark-cyan);
227
}
228
229
.tip-person,
230
.total-person {
231
font-size: 35px;
232
color: var(--primary-color);
233
}
234
235
.output>div>div>div>span:first-of-type {
236
text-transform: capitalize;
237
color: var(--white);
238
display: block;
239
}
240
241
.output>div>div>div>span:last-of-type {
242
color: var(--grayish-cyan);
243
}
244
245
246
/*END OF OUTPUT */
247
248
.active:not(input) {
249
background-color: var(--primary-color);
250
color: var(--very-dark-cyan);
251
transition: background 0.7s ease-in-out;
252
}
253
254
.correct {
255
border: lightgreen 2px solid;
256
}
257
258
.error {
259
border: red 2px solid;
260
}
261
262
.correct:focus,
263
.error:focus {
264
outline: none;
265
}
266
267
268
/* JAVASCRIPT CLASSES */
269
270
271
/* END OF JAVASCRIPT CLASSES */
272
273
274
/* FOR DESKTOP */
275
276
@media (min-width: 1200px) {
277
/* RESET */
278
html,
279
body,
280
main {
281
margin: 0;
282
}
283
/* END OF RESET */
284
/* GENERIC TAGS */
285
form {
286
width: 100%;
287
max-width: 900px;
288
border-radius: 15px;
289
overflow: hidden;
290
margin: auto;
291
padding-right: 15px;
292
display: flex;
293
width: fit-content;
294
background-color: var(--white);
295
}
296
input {
297
width: 90%;
298
}
299
aside {
300
display: none;
301
}
302
/* END OF GENERIC TAGS */
303
/* GENERIC CLASSES */
304
.output,
305
.input {
306
height: 400px;
307
}
308
.warning {
309
margin-left: 92px;
310
}
311
/* END OF GENERIC CLASSES */
312
/* INPUT */
313
.input button,
314
.input input#custom {
315
width: calc(100% / 3 - 20px);
316
}
317
.input {
318
width: 50%;
319
padding-bottom: 0;
320
}
321
.input legend {
322
margin-left: 25px;
323
}
324
/* END OF INPUT */
325
/* OUTPUT */
326
.output {
327
width: 50%;
328
margin: 22px;
329
padding: 0;
330
display: flex;
331
flex-direction: column;
332
justify-content: space-around;
333
}
334
.output div {
335
margin-left: 20px;
336
}
337
.output>div>div:first-of-type {
338
margin-top: -20px;
339
margin-bottom: 40px;
340
}
341
[type="reset"] {
342
display: none;
343
}
344
/* END OF OUTPUT */
345
}
JavaScript
1
54
54
1
<h1>
2
<span>spli</span>
3
<span>tter</span>
4
</h1>
5
6
<form action="post">
7
<div class="input">
8
<legend>
9
<label for="bill">bill</label>
10
<input type="number" name="bill" id="bill" class="correct">
11
</legend>
12
13
<legend>
14
<label for="custom">select tip %</label>
15
<button type="button">5%</button>
16
<button type="button" class="">10%</button>
17
<button type="button">15%</button>
18
<button type="button">25%</button>
19
<button type="button">50%</button>
20
<input placeholder="custom" name="custom" id="custom" class="">
21
</legend>
22
23
<legend>
24
<label for="people">Number of People</label>
25
<p class="warning" style="display: inline;">Can't be zero</p>
26
<input type="number" name="people" id="people" class="">
27
</legend>
28
</div>
29
30
<div class="output">
31
<div>
32
<div>
33
<div>
34
<span>tip amount</span>
35
<span>/ person</span>
36
</div>
37
38
<span class="tip-person" data-tip-person=""></span>
39
</div>
40
41
<div>
42
<div>
43
<span>Total</span>
44
<span>/ person</span>
45
</div>
46
47
<span class="total-person" data-total-person=""></span>
48
</div>
49
</div>
50
51
<button type="submit" style="display: block;">Calculate</button>
52
<button type="reset" class="" style="display: none;">Reset</button>
53
</div>
54
</form>
Live site: https://kaustubhmaladkar.github.io/Tip-Calculator/
Code on Github: https://github.com/KaustubhMaladkar/Tip-Calculator/
Advertisement
Answer
The problem comes from this line:
JavaScript
1
4
1
input:not(#custom) {
2
text-indent: 99.8%;
3
}
4
If you only want a alignment to the right, change it to:
JavaScript
1
4
1
input:not(#custom) {
2
text-align: right;
3
}
4
Working example:
JavaScript
1
110
110
1
const peopleElem = document.querySelector("#people");
2
const billElem = document.querySelector("#bill");
3
const submit = document.querySelector("[type="submit"]");
4
const form = document.querySelector("form");
5
const tipPerPersonElem = document.querySelector("[data-tip-person]");
6
const totalPerPersonElem = document.querySelector("[data-total-person]");
7
let billError = peopleError = false;
8
9
class TipCalc {
10
constructor() {
11
this.tipPerPerson = 0;
12
this.totalPerPerson = 0;
13
this.tip = 0
14
this.tipPercent = 0;
15
this.bill = parseFloat(billElem.value);
16
this.people = parseFloat(peopleElem.value);
17
}
18
19
getTip() {
20
const element = document.querySelector(".active");
21
if (!element) return 0;
22
if (element.tagName === "BUTTON") return this.tipPercent = element.innerText.replace("%", "");
23
return this.tipPercent = element.value.replace("%", "");
24
}
25
26
getTipPerPerson() {
27
this.getTip();
28
this.tip = ((this.tipPercent / 100) * this.bill);
29
this.tipPerPerson = this.tip / this.people;
30
return this.tipPerPerson;
31
}
32
33
getTotalPerPerson() {
34
this.getTipPerPerson();
35
this.totalPerPerson = (this.bill + this.tip) / this.people
36
return this.totalPerPerson;
37
}
38
}
39
40
const tipOptions = [document.querySelectorAll("button"), document.querySelector("#custom")];
41
tipOptions.forEach(option => {
42
if (option.tagName === "INPUT" && option.value.length) option.addEventListener("keyup", () => {
43
tipOptions.forEach(option => option.classList.remove("active"));
44
option.classList.toggle("active");
45
})
46
if (!(option.type == "submit")) option.addEventListener("click", () => {
47
tipOptions.forEach(option => option.classList.remove("active"));
48
option.classList.toggle("active");
49
})
50
})
51
52
form.addEventListener("submit", event => {
53
event.preventDefault();
54
checkInputForError(peopleElem, peopleError, true);
55
checkInputForError(billElem, billError, false);
56
if (billError || peopleError) return;
57
const tipCalculator = new TipCalc();
58
const tip = isNaN(tipCalculator.getTipPerPerson()) ? 0 : tipCalculator.getTipPerPerson();
59
const total = isNaN(tipCalculator.getTotalPerPerson()) ? 0 : tipCalculator.getTotalPerPerson();
60
const formatter = new Intl.NumberFormat(undefined, {
61
style: "currency",
62
currency: "USD",
63
signDisplay: "never"
64
});
65
tipPerPersonElem.innerText = formatter.format(tip);
66
totalPerPersonElem.innerText = formatter.format(total);
67
submit.style.display = "none";
68
const resetBtn = document.querySelector("[type="reset"]");
69
resetBtn.style.display = "block";
70
resetBtn.addEventListener("click", () => {
71
reset()
72
resetBtn.style.display = "none";
73
submit.style.display = "block";
74
})
75
})
76
77
document.addEventListener("DOMContentLoaded", () => {
78
reset()
79
})
80
81
peopleElem.addEventListener("keyup", () => checkInputForError(peopleElem, peopleError, true));
82
billElem.addEventListener("keyup", () => checkInputForError(billElem, billError, false));
83
84
function checkInputForError(input, error, showError) {
85
const value = input.value.trim() || 0;
86
if (!value || isNaN(parseFloat(value)) || parseFloat(value) == 0) {
87
if (showError) document.querySelector(".warning").style.display = "inline";
88
input.classList.add("error");
89
error = true;
90
} else {
91
if (showError) document.querySelector(".warning").style.display = "none";
92
input.classList.remove("error");
93
input.classList.add("correct");
94
error = false;
95
}
96
}
97
98
function reset(submit = false) {
99
const tipPerPersonElem = document.querySelector("[data-tip-person]");
100
const totalPerPersonElem = document.querySelector("[data-total-person]");
101
tipPerPersonElem.innerText = "";
102
totalPerPersonElem.innerText = "";
103
console.log(tipPerPersonElem.innerText, totalPerPersonElem.innerText, "reset", submit);
104
tipOptions.forEach(option => option.classList.remove("active"));
105
document.querySelectorAll("input").forEach(input => {
106
input.classList.remove("correct");
107
input.classList.remove("error");
108
input.value = "";
109
})
110
}
JavaScript
1
345
345
1
:root {
2
--primary-color: hsl(172, 67%, 45%);
3
--very-dark-cyan: hsl(183, 100%, 15%);
4
--dark-grayish-cyan: hsl(186, 14%, 43%);
5
--grayish-cyan: hsl(184, 14%, 56%);
6
--light-grayish-cyan: hsl(185, 41%, 84%);
7
--very-light-grayish-cyan: hsl(189, 41%, 97%);
8
--white: hsl(0, 0%, 100%);
9
--primary-font-size: 24px;
10
--primary-font-family: 'Space Mono', monospace;
11
}
12
13
14
/* GLOABAL TAGS */
15
16
body {
17
width: 100%;
18
margin: 0;
19
overflow: hidden;
20
font-family: var(--primary-font-family);
21
background-color: var(--light-grayish-cyan);
22
}
23
24
header {
25
text-align: center;
26
}
27
28
h1 {
29
color: var(--very-dark-cyan);
30
margin-top: 0;
31
text-transform: uppercase;
32
}
33
34
h1 span {
35
display: block;
36
margin: 0;
37
}
38
39
label {
40
display: block;
41
text-transform: capitalize;
42
}
43
44
button {
45
outline: none;
46
border: none;
47
text-align: center;
48
background-color: var(--very-dark-cyan);
49
font-size: var(--primary-font-size);
50
color: var(--white);
51
text-transform: capitalize;
52
margin: 8px;
53
padding-top: 8px;
54
padding-bottom: 8px;
55
border-radius: 4px;
56
cursor: pointer;
57
}
58
59
legend {
60
margin-bottom: 8px;
61
}
62
63
64
/* Chrome,
65
Safari,
66
Edge, */
67
68
69
/* Opera */
70
71
input::-webkit-outer-spin-button,
72
input::-webkit-inner-spin-button {
73
-webkit-appearance: none;
74
margin: 0;
75
}
76
77
78
/* Firefox */
79
80
input[type=number] {
81
-moz-appearance: textfield;
82
}
83
84
input {
85
display: block;
86
border: none;
87
background-color: var(--very-light-grayish-cyan);
88
font-size: var(--primary-font-size);
89
height: 30px;
90
color: var(--very-dark-cyan);
91
background-repeat: no-repeat;
92
background-position: left center;
93
}
94
95
input:not(#custom) {
96
text-align: right;
97
}
98
99
aside {
100
font-size: 11px;
101
text-align: center;
102
}
103
104
aside a {
105
color: hsl(228, 45%, 44%);
106
}
107
108
109
/* END OF GLOBAL TAGS GENERIC IDs */
110
111
#bill {
112
background-image: url('https://kaustubhmaladkar.github.io/Tip-Calculator/images/icon-dollar.svg');
113
}
114
115
#people {
116
background-image: url('https://kaustubhmaladkar.github.io/Tip-Calculator/images/icon-person.svg');
117
}
118
119
120
/* END OF GENERIC IDs GENERIC CLASSES*/
121
122
button,
123
#custom {
124
width: calc(50% - 20px);
125
font-weight: bold;
126
}
127
128
129
/* END OF GENERIC CLASSES */
130
131
132
/* INPUT */
133
134
.input {
135
background-color: var(--white);
136
color: var(--dark-grayish-cyan);
137
border-top-right-radius: 20px;
138
border-top-left-radius: 20px;
139
margin-top: 20px;
140
padding-bottom: 30px;
141
}
142
143
.input legend {
144
margin-top: 20px;
145
margin-left: 20px;
146
}
147
148
legend:nth-of-type(2) label {
149
width: 100%;
150
}
151
152
legend:nth-of-type(2) {
153
display: flex;
154
flex-wrap: wrap;
155
}
156
157
[for="people"] {
158
display: inline;
159
}
160
161
.warning {
162
display: none;
163
/* margin-left: 92px; */
164
color: red;
165
font-size: 12px;
166
background-color: transparent;
167
}
168
169
input#custom {
170
background-color: var(--white);
171
color: var(--dark-grayish-cyan);
172
margin-top: 12px;
173
margin-left: 2px;
174
padding-bottom: 8px;
175
opacity: 1;
176
}
177
178
input#custom::placeholder {
179
text-transform: capitalize;
180
color: var(--dark-grayish-cyan);
181
opacity: 1;
182
}
183
184
185
/* END OF INPUT */
186
187
188
/*OUTPUT*/
189
190
.output {
191
background-color: var(--very-dark-cyan);
192
display: flex;
193
margin-top: -8px;
194
justify-content: center;
195
align-items: center;
196
flex-direction: column;
197
border-radius: 10px;
198
}
199
200
.output div,
201
.output span {
202
width: 100%;
203
}
204
205
.output>div>div {
206
display: flex;
207
gap: 15px;
208
}
209
210
.output>div>div:first-of-type {
211
margin-top: 30px;
212
margin-bottom: 15px;
213
}
214
215
.output>div>div:last-of-type {
216
margin-top: 15px;
217
margin-bottom: 30px;
218
}
219
220
[type="submit"],
221
[type="reset"] {
222
font-family: var(--primary-font-family);
223
background-color: var(--primary-color);
224
width: 90%;
225
text-align: center;
226
color: var(--very-dark-cyan);
227
}
228
229
.tip-person,
230
.total-person {
231
font-size: 35px;
232
color: var(--primary-color);
233
}
234
235
.output>div>div>div>span:first-of-type {
236
text-transform: capitalize;
237
color: var(--white);
238
display: block;
239
}
240
241
.output>div>div>div>span:last-of-type {
242
color: var(--grayish-cyan);
243
}
244
245
246
/*END OF OUTPUT */
247
248
.active:not(input) {
249
background-color: var(--primary-color);
250
color: var(--very-dark-cyan);
251
transition: background 0.7s ease-in-out;
252
}
253
254
.correct {
255
border: lightgreen 2px solid;
256
}
257
258
.error {
259
border: red 2px solid;
260
}
261
262
.correct:focus,
263
.error:focus {
264
outline: none;
265
}
266
267
268
/* JAVASCRIPT CLASSES */
269
270
271
/* END OF JAVASCRIPT CLASSES */
272
273
274
/* FOR DESKTOP */
275
276
@media (min-width: 1200px) {
277
/* RESET */
278
html,
279
body,
280
main {
281
margin: 0;
282
}
283
/* END OF RESET */
284
/* GENERIC TAGS */
285
form {
286
width: 100%;
287
max-width: 900px;
288
border-radius: 15px;
289
overflow: hidden;
290
margin: auto;
291
padding-right: 15px;
292
display: flex;
293
width: fit-content;
294
background-color: var(--white);
295
}
296
input {
297
width: 90%;
298
}
299
aside {
300
display: none;
301
}
302
/* END OF GENERIC TAGS */
303
/* GENERIC CLASSES */
304
.output,
305
.input {
306
height: 400px;
307
}
308
.warning {
309
margin-left: 92px;
310
}
311
/* END OF GENERIC CLASSES */
312
/* INPUT */
313
.input button,
314
.input input#custom {
315
width: calc(100% / 3 - 20px);
316
}
317
.input {
318
width: 50%;
319
padding-bottom: 0;
320
}
321
.input legend {
322
margin-left: 25px;
323
}
324
/* END OF INPUT */
325
/* OUTPUT */
326
.output {
327
width: 50%;
328
margin: 22px;
329
padding: 0;
330
display: flex;
331
flex-direction: column;
332
justify-content: space-around;
333
}
334
.output div {
335
margin-left: 20px;
336
}
337
.output>div>div:first-of-type {
338
margin-top: -20px;
339
margin-bottom: 40px;
340
}
341
[type="reset"] {
342
display: none;
343
}
344
/* END OF OUTPUT */
345
}
JavaScript
1
54
54
1
<h1>
2
<span>spli</span>
3
<span>tter</span>
4
</h1>
5
6
<form action="post">
7
<div class="input">
8
<legend>
9
<label for="bill">bill</label>
10
<input type="number" name="bill" id="bill" class="correct">
11
</legend>
12
13
<legend>
14
<label for="custom">select tip %</label>
15
<button type="button">5%</button>
16
<button type="button" class="">10%</button>
17
<button type="button">15%</button>
18
<button type="button">25%</button>
19
<button type="button">50%</button>
20
<input placeholder="custom" name="custom" id="custom" class="">
21
</legend>
22
23
<legend>
24
<label for="people">Number of People</label>
25
<p class="warning" style="display: inline;">Can't be zero</p>
26
<input type="number" name="people" id="people" class="">
27
</legend>
28
</div>
29
30
<div class="output">
31
<div>
32
<div>
33
<div>
34
<span>tip amount</span>
35
<span>/ person</span>
36
</div>
37
38
<span class="tip-person" data-tip-person=""></span>
39
</div>
40
41
<div>
42
<div>
43
<span>Total</span>
44
<span>/ person</span>
45
</div>
46
47
<span class="total-person" data-total-person=""></span>
48
</div>
49
</div>
50
51
<button type="submit" style="display: block;">Calculate</button>
52
<button type="reset" class="" style="display: none;">Reset</button>
53
</div>
54
</form>