-
Notifications
You must be signed in to change notification settings - Fork 27.1k
/
Copy pathugly-controls.html
155 lines (138 loc) · 4.05 KB
/
ugly-controls.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Ugly controls basic styling</title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Josefin Sans', sans-serif;
margin: 20px auto;
max-width: 400px;
}
form > div {
margin-bottom: 20px;
}
button, label, input, select, progress, meter {
display: block;
font-family: inherit;
font-size: 100%;
margin: 0;
box-sizing: border-box;
width: 100%;
padding: 5px;
height: 30px;
}
select {
appearance: none;
}
.select-wrapper {
position: relative;
}
.select-wrapper::after {
content: "▼";
font-size: 1rem;
top: 6px;
right: 10px;
position: absolute;
}
input[type="text"],
input[type="datetime-local"],
input[type="color"],
select {
box-shadow: inset 1px 1px 3px #ccc;
border-radius: 5px;
}
label {
margin-bottom: 5px;
}
button {
width: 60%;
margin: 0 auto;
}
</style>
</head>
<body>
<form>
<div>
<label for="select">Select box:</label>
<div class="select-wrapper">
<select id="select" name="select">
<option>Banana</option>
<option>Cherry</option>
<option>Lemon</option>
</select>
</div>
</div>
<div>
<label for="myFruit">"Favorite fruit?" datalist:</label>
<input type="text" name="myFruit" id="myFruit" list="mySuggestion">
<datalist id="mySuggestion">
<option>Apple</option>
<option>Banana</option>
<option>Blackberry</option>
<option>Blueberry</option>
<option>Lemon</option>
<option>Lychee</option>
<option>Peach</option>
<option>Pear</option>
</datalist>
</div>
<div>
<label for="date1">Datetime local: </label>
<input id="date1" name="date1" type="datetime-local">
</div>
<div>
<label for="range">Range: </label>
<input id="range" name="range" type="range">
</div>
<div>
<label for="color">Color: </label>
<input id="color" name="color" type="color">
</div>
<div>
<label for="file">File picker: </label>
<input id="file" name="file" type="file" multiple>
<ul id="file-list">
</ul>
</div>
<div>
<label for="progress">Progress: </label>
<progress max="100" value="75" id="progress">75/100</progress>
</div>
<div>
<label for="meter">Meter: </label>
<meter id="meter" min="0" max="100" value="75" low="33" high="66" optimum="50">75</meter>
</div>
<div><button>Submit?</button></div>
</form>
<script>
const fileInput = document.querySelector('#file');
const fileList = document.querySelector('#file-list');
fileInput.addEventListener('change', updateFileList);
function updateFileList() {
while(fileList.firstChild) {
fileList.removeChild(fileList.firstChild);
}
let curFiles = fileInput.files;
if(!(curFiles.length === 0)) {
for(let i = 0; i < curFiles.length; i++) {
const listItem = document.createElement('li');
listItem.textContent = 'File name: ' + curFiles[i].name + '; file size ' + returnFileSize(curFiles[i].size) + '.';
fileList.appendChild(listItem);
}
}
}
function returnFileSize(number) {
if(number < 1024) {
return number + 'bytes';
} else if(number >= 1024 && number < 1048576) {
return (number/1024).toFixed(1) + 'KB';
} else if(number >= 1048576) {
return (number/1048576).toFixed(1) + 'MB';
}
}
</script>
</body>
</html>