aboutsummaryrefslogtreecommitdiff
path: root/cool-inputs/src/styles.css
blob: 9258b4a6288e526a6a96f66724806a485dac067b (plain) (blame)
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
/* Global */

:root {
  --focus-color: forestgreen;
  --input-margin: 0.4em;
  --transition-duration: 0.2s;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 21px sans-serif;
  background-color: white;
}

/* Core style */

form {
  height: 100%;
  max-width: 20em;
  margin-left: auto;
  margin-right: auto;

  /* Align inputs vertically and
   * center them vertically and horizontally
   */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

form > section {
  width: 100%;
}

input {
  width: 100%;

  border: 0;
  border-bottom: 1px solid grey;
  padding: 0.4em;
  padding-left: 0;

  box-sizing: border-box;
  font-size: inherit;
  margin-bottom: 0.5em;
}

input:focus, button:focus {
  outline: 0;
}

/* Where the magic happens */

.input-selection {
  position: relative;
  margin-top: 0.7em;
}

.input-selection label {
  transition: var(--transition-duration);
  width: inherit;
  height: inherit;

  position: absolute;
  margin-top: var(--input-margin);
  scale: 1em;
  color: grey;
  left: 0;
}

.input-selection input::placeholder {
  /* Don't show the placeholder when the label is on top */
  opacity: 0;
  color: grey;
}

.input-selection:hover > input::placeholder, 
.input-selection > input:focus::placeholder {
  /* When hovering on the input, or when having clicked on it,
   * show the placeholder
   */
  opacity: 1;
}

.input-selection:hover > label, 
.input-selection > input:not(:placeholder-shown) + label,
.input-selection > input:focus + label {
  /* When hovering, typing or having typed something in an input, 
   * make the label smaller, color it and then move it up
   */
  font-size: 0.7em;
  color: var(--focus-color);
  transform: translate(0, -1.2em);
}

.input-selection:hover > input,
.input-selection > input:focus {
  /* When hovering or clicked on it, make it the focus color */
  border-color: var(--focus-color) !important;
  caret-color: var(--focus-color);
  /* When hovering or clicked on it, make the bottom border wider (taller) */
  border-width: 2px !important;
  padding-bottom: calc(var(--input-margin) - 1px) !important;
}