_custom-forms.scss 8.31 KB
Newer Older
1
2
3
4
5
// Embedded icons from Open Iconic.
// Released under MIT and copyright 2014 Waybury.
// http://useiconic.com/open

// Checkboxes and radios
Mark Otto's avatar
Mark Otto committed
6
7
8
//
// Base class takes care of all the key behavioral aspects.

9
.c-input {
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
  position: relative;
  display: inline;
  padding-left: 1.5rem;
  color: #555;
  cursor: pointer;

  > input {
    position: absolute;
    z-index: -1; // Put the input behind the label so it doesn't overlay text
    opacity: 0;

    &:focus ~ .c-indicator {
      box-shadow: 0 0 0 .075rem #fff, 0 0 0 .2rem #0074d9;
    }

    &:checked ~ .c-indicator {
      color: #fff;
      background-color: #0074d9;
    }

    &:active ~ .c-indicator {
      color: #fff;
      background-color: #84c6ff;
    }
  }

  + .c-input {
    margin-left: 1rem;
  }
39
40
}

Mark Otto's avatar
Mark Otto committed
41
42
43
44
// Custom indicator
//
// Generates a shadow element to create our makeshift checkbox/radio background.

45
.c-indicator {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 1rem;
  height: 1rem;
  font-size: 65%;
  line-height: 1rem;
  color: #eee;
  text-align: center;
  user-select: none;
  background-color: #eee;
  background-repeat: no-repeat;
  background-position: center center;
  background-size: 50% 50%;
61
62
}

Mark Otto's avatar
Mark Otto committed
63
64
65
// Checkboxes
//
// Tweak just a few things for checkboxes.
66

Mark Otto's avatar
Mark Otto committed
67
.c-checkbox {
68
69
70
  .c-indicator {
    border-radius: .25rem;
  }
71

72
73
74
  input:checked ~ .c-indicator {
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgOCA4IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA4IDgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHBhdGggZmlsbD0iI0ZGRkZGRiIgZD0iTTYuNCwxTDUuNywxLjdMMi45LDQuNUwyLjEsMy43TDEuNCwzTDAsNC40bDAuNywwLjdsMS41LDEuNWwwLjcsMC43bDAuNy0wLjdsMy41LTMuNWwwLjctMC43TDYuNCwxTDYuNCwxeiINCgkvPg0KPC9zdmc+DQo=);
  }
75
76
}

Mark Otto's avatar
Mark Otto committed
77
78
79
// Radios
//
// Tweak just a few things for radios.
80

Mark Otto's avatar
Mark Otto committed
81
.c-radio {
82
83
84
  .c-indicator {
    border-radius: 50%;
  }
85

Mark Otto's avatar
Mark Otto committed
86
  input:checked ~ .c-indicator {
87
88
    background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgOCA4IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA4IDgiIHhtbDpzcGFjZT0icHJlc2VydmUiPg0KPHBhdGggZmlsbD0iI0ZGRkZGRiIgZD0iTTQsMUMyLjMsMSwxLDIuMywxLDRzMS4zLDMsMywzczMtMS4zLDMtM1M1LjcsMSw0LDF6Ii8+DQo8L3N2Zz4NCg==);
  }
89
90
}

91
// Alternately, use another character
92
.control-x input:checked ~ .control-indicator {
93
  background-image: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iOHB4IiBoZWlnaHQ9IjhweCIgdmlld0JveD0iMCAwIDggO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ik0wLDN2Mmg4VjNIMHoiLz4NCjwvc3ZnPg0K);
97
98
}

99
100
101
102
103
104
// Layout options
//
// By default radios and checkboxes are `inline-block` with no additional spacing
// set. Use these optional classes to tweak the layout.

.c-inputs-stacked {
105
106
107
108
109
110
111
112
113
114
115
116
117
  .c-input {
    display: inline;

    &:after {
      display: block;
      margin-bottom: .25rem;
      content: "";
    }

    + .c-input {
      margin-left: 0;
    }
  }
118
119
}

120
121
122
// Select
//
// Replaces the browser default select with a custom one.
123
124

.select {
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  position: relative;
  display: inline-block;
  color: #555;

  > select {
    display: inline-block;
    width: 100%;
    padding: .5rem 2.25rem .5rem 1rem;
    margin: 0;
    line-height: 1.5;
    color: #555;
    cursor: pointer;
    background-color: #eee;
    border: 0;
    border-radius: .25rem;
    outline: 0;
    -webkit-appearance: none;
    appearance: none;

    &:focus {
      box-shadow: 0 0 0 .075rem #fff, 0 0 0 .2rem #0074d9;

      // Undo the Firefox inner focus ring
      &:-moz-focusring {
        color: transparent;
        text-shadow: 0 0 0 #000;
      }
    }

    &:active {
      color: #fff;
      background-color: #0074d9;
    }

    // Hide the arrow in IE10 and up
    &::-ms-expand {
      display: none;
    }
  }

  // Dropdown arrow
  &:after {
    position: absolute;
    top: 50%;
    right: 1.25rem;
    display: inline-block;
    width: 0;
    height: 0;
    margin-top: -.15rem;
    pointer-events: none;
    content: "";
    border-top: .35rem solid;
    border-right: .35rem solid transparent;
    border-bottom: .35rem solid transparent;
    border-left: .35rem solid transparent;
  }
181
182
}

183
184
185
186
187
// Hover state
// Uncomment if you need it, but be aware of the sticky iOS states.
// .select select:hover {
//   background-color: #ddd;
// }
188
189


190
// Media query to target Firefox only
191
@-moz-document url-prefix() {
192
193
194
195
196
197
198
199
200
201
202
  // Firefox hack to hide the arrow
  .select select {
    padding-right: 1rem;
    text-indent: 0.01px;
    text-overflow: "";
  }

  // <option> elements inherit styles from <select>, so reset them.
  .select option {
    background-color: #fff;
  }
203
204
}

205
// IE9 hack to hide the arrow
206
@media screen and (min-width:0\0) {
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  .select select {
    z-index: 1;
    padding: .5rem 1.5rem .5rem 1rem;
  }
  .select:after {
    z-index: 5;
  }
  .select:before {
    position: absolute;
    top: 0;
    right: 1rem;
    bottom: 0;
    z-index: 2;
    display: block;
    width: 1.5rem;
    content: "";
    background-color: #eee;
  }
  .select select:hover,
  .select select:focus,
  .select select:active {
    color: #555;
    background-color: #eee;
  }
231
232
}

233
234
235
// File
//
// Custom file input.
236
237

.file {
238
239
240
241
  position: relative;
  display: inline-block;
  height: 2.5rem;
  cursor: pointer;
242
243
}
.file input {
244
245
246
247
  min-width: 14rem;
  margin: 0;
  filter: alpha(opacity=0);
  opacity: 0;
248
249
}
.file-custom {
250
251
252
253
254
255
256
257
258
259
260
261
262
263
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 5;
  height: 2.5rem;
  padding: .5rem 1rem;
  line-height: 1.5;
  color: #555;
  user-select: none;
  background-color: #fff;
  border: .075rem solid #ddd;
  border-radius: .25rem;
  box-shadow: inset 0 .2rem .4rem rgba(0,0,0,.05);
264
265
}
.file-custom:after {
266
  content: "Choose file...";
267
268
}
.file-custom:before {
269
270
271
272
273
274
275
276
277
278
279
280
281
282
  position: absolute;
  top: -.075rem;
  right: -.075rem;
  bottom: -.075rem;
  z-index: 6;
  display: block;
  height: 2.5rem;
  padding: .5rem 1rem;
  line-height: 1.5;
  color: #555;
  content: "Browse";
  background-color: #eee;
  border: .075rem solid #ddd;
  border-radius: 0 .25rem .25rem 0;
283
284
}

285
// Focus state
286
.file input:focus ~ .file-custom {
287
  box-shadow: 0 0 0 .075rem #fff, 0 0 0 .2rem #0074d9;
288
}