Skip to content

Commit 7f4696a

Browse files
committed
Initial commit
0 parents  commit 7f4696a

File tree

5 files changed

+166
-0
lines changed

5 files changed

+166
-0
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TemperatureConverter
2+

index.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>Document</title>
9+
<link rel="stylesheet" href="style.css">
10+
</head>
11+
12+
<body>
13+
<main>
14+
<form>
15+
<div class="container">
16+
<input type="number" name="degrees" autocomplete="off" required>
17+
<label class="degrees">Degrees</label>
18+
</div>
19+
<div class="container">
20+
<select name="type">
21+
<option value="F">Fahrenheit</option>
22+
<option value="C">Celcius</option>
23+
</select>
24+
<label class="type">Type</label>
25+
</div>
26+
<button type="submit">Convert</button>
27+
</form>
28+
<div class="result">
29+
<p>Result</p>
30+
<p></p>
31+
</div>
32+
</main>
33+
<script src="script.js"></script>
34+
</body>
35+
36+
</html>

script.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const form = document.querySelector("form");
2+
const resultArea = document.querySelector(".result p:nth-child(2)");
3+
const convert2F = degree => (degree * 1.8 + 32).toFixed(2);
4+
const convert2C = degree => ((degree - 32) * 0.5556).toFixed(2);
5+
const submitBtn = e => {
6+
e.preventDefault();
7+
const degrees = Number(e.target.degrees.value) || 0;
8+
const type = e.target.type.value;
9+
const strategy =
10+
{
11+
C: convert2F,
12+
F: convert2C,
13+
};
14+
const result = strategy[type](degrees);
15+
resultArea.innerHTML = `${result} ${type === "C" ? "&#8457" : " &#8451"}`;
16+
};
17+
form.addEventListener("submit",submitBtn);

style.css

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
:root {
2+
--desc-font-size: 0.8rem;
3+
--desc-font-color: rgb(153, 153, 153);
4+
}
5+
6+
* {
7+
margin: 0;
8+
padding: 0;
9+
box-sizing: border-box;
10+
}
11+
12+
body {
13+
background-color: rgb(144, 182, 169);
14+
}
15+
16+
input::-webkit-outer-spin-button,
17+
input::-webkit-inner-spin-button {
18+
-webkit-appearance: none;
19+
margin: 0;
20+
}
21+
22+
input[type="number"] {
23+
-moz-appearance: textfield;
24+
}
25+
26+
main {
27+
width: 40vw;
28+
height: 30vh;
29+
margin-left: auto;
30+
margin-right: auto;
31+
margin-top: 2rem;
32+
padding: 1.5rem;
33+
background-color: white;
34+
box-shadow: 1px 1px 5px black;
35+
border-radius: 10px;
36+
}
37+
38+
form {
39+
display: flex;
40+
justify-content: space-between;
41+
flex-wrap: wrap;
42+
}
43+
44+
form button {
45+
padding: 0.75rem;
46+
border-radius: 5px;
47+
border: none;
48+
color: white;
49+
background-color: blue;
50+
}
51+
52+
.container {
53+
position: relative;
54+
}
55+
56+
.container * {
57+
border: 1px solid lightgray;
58+
position: relative;
59+
}
60+
61+
.container input,
62+
.container select {
63+
padding: 0.75rem;
64+
border-radius: 8px;
65+
}
66+
67+
.container .type {
68+
position: absolute;
69+
top: -1.25rem;
70+
left: 0;
71+
color: var(--desc-font-color);
72+
font-size: var(--desc-font-size);
73+
border: none;
74+
}
75+
76+
.container .degrees {
77+
position: absolute;
78+
top: 50%;
79+
left: 5%;
80+
transform: translateY(-50%);
81+
color: var(--desc-font-color);
82+
border: none;
83+
transition: all 0.1s ease;
84+
pointer-events: none;
85+
}
86+
87+
.container input[type="number"]:focus~.degrees,
88+
.container input[type="number"]:not(:focus):valid~.degrees {
89+
top: -1.25rem;
90+
left: 0;
91+
font-size: var(--desc-font-size);
92+
transform: translateY(0);
93+
}
94+
95+
.result {
96+
margin-top: 1rem;
97+
min-height: 2.5rem;
98+
}
99+
100+
.result p:nth-child(1) {
101+
font-size: var(--desc-font-size);
102+
color: var(--desc-font-color);
103+
}
104+
105+
.result p:nth-child(2) {
106+
margin-top: 0.1rem;
107+
font-size: 1.25rem;
108+
font-weight: 600;
109+
}

0 commit comments

Comments
 (0)