forked from mdo/wtf-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
275 lines (222 loc) · 13.9 KB
/
index.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<link href="public/ico/favicon.ico" rel="shortcut icon" type="image/x-icon">
<title>
WTF, forms?
</title>
<link rel="stylesheet" href="wtf-forms.css">
<link rel="stylesheet" href="docs.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic|PT+Mono&subset=latin,cyrillic">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-146052-18', 'wtfforms.com');
ga('send', 'pageview');
</script>
</head>
<body>
<header class="masthead">
<div class="container">
<span class="icon">✈</span>
<h1>WTF, forms?</h1>
<p class="lead">Friendlier HTML form controls with a little CSS magic. Designed for IE9+, as well as the latest Chrome, Safari, and Firefox.</p>
<p class="lead">Created by <a href="https://twitter.com/mdo/">@mdo</a>.</p>
<p class="masthead-links">
<a href="https://github.com/mdo/wtf-forms/">
<span class="icon icon-github-circled"></span>
</a>
<a href="https://twitter.com/mdo/">
<span class="icon icon-twitter"></span>
</a>
</p>
</div>
</header>
<div class="container">
<script type="text/javascript" src="//cdn.fusionads.net/fusion.js?zoneid=1332&serve=C6SDP2Y&placement=wtfforms" id="_fusionads_js"></script>
<h3>Checkboxes and radios</h3>
<form class="controls-stacked">
<label class="control checkbox">
<input type="checkbox">
<span class="control-indicator"></span>
Check this custom checkbox
</label>
</form>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><label</span> <span class="na">class=</span><span class="s">"control checkbox"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"checkbox"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"control-indicator"</span><span class="nt">></span></span>
Check this custom checkbox
<span class="nt"></label></span>
</code></pre></div>
<form class="controls-stacked">
<label class="control radio">
<input type="radio" id="radio1" name="radio">
<span class="control-indicator"></span>
Toggle this custom radio
</label>
<label class="control radio">
<input type="radio" id="radio2" name="radio">
<span class="control-indicator"></span>
Or toggle this other custom radio
</label>
</form>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><label</span> <span class="na">class=</span><span class="s">"control radio"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"radio"</span> <span class="na">id=</span><span class="s">"radio1"</span> <span class="na">name=</span><span class="s">"radio"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"control-indicator"</span><span class="nt">></span></span>
Toggle this custom radio
<span class="nt"></label></span>
<span class="nt"><label</span> <span class="na">class=</span><span class="s">"control radio"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"radio"</span> <span class="na">id=</span><span class="s">"radio2"</span> <span class="na">name=</span><span class="s">"radio"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"control-indicator"</span><span class="nt">></span></span>
Or toggle this other custom radio
<span class="nt"></label></span>
</code></pre></div>
<p>Each checkbox and radio is wrapped in a <code><label></code> for three reasons:</p>
<ol>
<li>It provides a larger hit areas for checking the control.</li>
<li>It provides a helpful and semantic wrapper to help us replace the default <code><input></code>s.</li>
<li>It triggers the state of the <code><input></code> automatically, meaning no JavaScript is required.</li>
</ol>
<p>We hide the default <code><input></code> with <code>opacity</code> and instead use the <code><span class="control-indicator"></code> within the <code><label></code> to build a new custom form control.</p>
<p>With the sibling selector (<code>~</code>), we use the <code>:checked</code> state to trigger a makeshift checked state on the custom control.</p>
<p>In the checked states, we use <strong>base64 embedded SVG icons</strong> from <a href="http://useiconic.com/open">Open Iconic</a>. This provides us the best control for styling and positioning across browsers and devices.</p>
<h4>Alternate icons</h4>
<p>By default, checkboxes use a checkmark and radios use an filled circle. Also included are two modifier classes, <code>.control-x</code> and <code>.control-dash</code>, to change things up should the need arise.</p>
<form class="controls-inline">
<label class="control checkbox control-x">
<input type="checkbox" checked>
<span class="control-indicator"></span>
</label>
<label class="control checkbox control-dash">
<input type="checkbox" checked>
<span class="control-indicator"></span>
</label>
<label class="control radio control-x">
<input type="radio" id="radioIcon1" name="radio-icon-x" checked>
<span class="control-indicator"></span>
</label>
<label class="control radio control-dash">
<input type="radio" id="radioIcon2" name="radio-icon-dash" checked>
<span class="control-indicator"></span>
</label>
</form>
<p>Add the modifier classes to the <code><label></code>, like so:</p>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><label</span> <span class="na">class=</span><span class="s">"control checkbox control-x"</span><span class="nt">></span>...<span class="nt"></label></span>
</code></pre></div>
<p>Want to customize the icons further, or use other ones? <a href="http://useiconic.com/open">Download Open Iconic</a>—included are font files, PNGs, and SVGs.</p>
<h3>Select menu</h3>
<form class="controls-stacked">
<label class="select">
<select>
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</label>
</form>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><label</span> <span class="na">class=</span><span class="s">"select"</span><span class="nt">></span>
<span class="nt"><select></span>
<span class="nt"><option</span> <span class="na">selected</span><span class="nt">></span>Open this select menu<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">"1"</span><span class="nt">></span>One<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">"2"</span><span class="nt">></span>Two<span class="nt"></option></span>
<span class="nt"><option</span> <span class="na">value=</span><span class="s">"3"</span><span class="nt">></span>Three<span class="nt"></option></span>
<span class="nt"></select></span>
<span class="nt"></label></span>
</code></pre></div>
<p>Similar to the checkboxes and radios, we wrap the <code><select></code> in a <code><label></code> as a semantic wrapper that we can generate custom styles on with CSS's generated content.</p>
<p>The <code><select></code> has quite a few styles to override and includes a few hacks to get things done. Here's what's happening:</p>
<ul>
<li>The <code>appearance</code> is reset to <code>none</code> for nearly all styles to correctly apply across modern browsers (meaning not IE9).</li>
<li>The <code>:-moz-focusring</code> is overridden so that on focus there's no inner border in Firefox.</li>
<li>The arrow is hidden in Firefox with a media query hack. (There's a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=649849">longstanding open bug</a> for a native method of addressing this.)</li>
<li>The arrow is hidden in IE10+ with a simple selector.</li>
<li>The arrow is hidden in IE9 with a separate media query hack which generates another pseudo-element to literally mask it. Not ideal, but doable.</li>
</ul>
<p><strong>Heads up!</strong> This one comes with some quirks right now:</p>
<ul>
<li>Clickability is limited in IE9.</li>
<li>Firefox's dropdown of <code>option</code>s looks rather ugly.</li>
<li>The custom caret is unable to receive the selected state's <code>color</code>.</li>
</ul>
<p>Any ideas on improving these are most welcome.</p>
<h3>Multiple select</h3>
<form class="controls-stacked">
<label class="select-multiple">
<select multiple>
<option selected>Open this select menu</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</label>
</form>
<h3>File browser</h3>
<form class="controls-stacked">
<label class="file">
<input type="file" id="file">
<span class="file-custom"></span>
</label>
</form>
<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><label</span> <span class="na">class=</span><span class="s">"file"</span><span class="nt">></span>
<span class="nt"><input</span> <span class="na">type=</span><span class="s">"file"</span> <span class="na">id=</span><span class="s">"file"</span><span class="nt">></span>
<span class="nt"><span</span> <span class="na">class=</span><span class="s">"file-custom"</span><span class="nt">></span></span>
<span class="nt"></label></span>
</code></pre></div>
<p>The file input is the most gnarly of the bunch. Here's how it works:</p>
<ul>
<li>We wrap the <code><input></code> in a <code><label></code> so the custom control properly triggers the file browser.</li>
<li>We hide the default file <code><input></code> via <code>opacity</code>.</li>
<li>We use <code>:after</code> to generate a custom background and directive (<em>Choose file...</em>).</li>
<li>We use <code>:before</code> to generate and position the <em>Browse</em> button.</li>
<li>We declare a <code>height</code> on the <code><input></code> for proper spacing for surrounding content.</li>
</ul>
<p>In other words, it's an entirely custom element, all generated via CSS.</p>
<p><strong>Heads up!</strong> The custom file input is currently unable to update the <em>Choose file...</em> text with the filename. Without JavaScript, this might not be possible to change, but I'm open to ideas.</p>
<h3>FAQs</h3>
<h4>What about every other form control?</h4>
<p>For the time being, <strong>WTF, forms?</strong> is limited to checkboxes, radio buttons, select menus, and file inputs. Additional custom inputs will depend on browser support.</p>
<h4>Why are there no <code>for</code> attributes?</h4>
<p>We nest our <code><input></code>s and <code><select></code>s within a <code><label></code>, so there's no need to specify a <code>for</code> attribute as the browser will automatically associate the two.</p>
<h4>What about <code>hover</code> states?</h4>
<p>Basic hover styles have been included, but they've been commented out because they are sticky on iOS. Uncomment if you really need it.</p>
<h4>Does this require JavaScript?</h4>
<p>Not for the time being, however, the file input might be better off with it.</p>
<h4>Will this be added to Bootstrap?</h4>
<p>Possibly, but not until v4 at the earliest.</p>
<h4>Is this screen reader friendly?</h4>
<p>Honestly, no idea right now.</p>
<h3>Changelog</h3>
<p>For a full changelog, visit the <a href="https://github.com/mdo/wtf-forms/releases">releases page on GitHub</a>.</p>
<p>This project utilizes <a href="http://semver.org">SemVer</a> for versioning releases for maximum backward compatibility.</p>
</div>
<footer class="footer">
<p><3</p>
<p>Made with all the love in the world by <a href="https://twitter.com/mdo/">@mdo</a>.</p>
<p>Open sourced under MIT. Copyright 2014.</p>
<p>Icons for checkbox and radio from <a href="http://useiconic.com/open">Open Iconic</a>.</p>
<ul class="quick-links">
<li>
<iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=mdo&repo=wtf-forms&type=watch&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="112" height="20"></iframe>
</li>
<li>
<iframe class="github-btn" src="http://ghbtns.com/github-btn.html?user=mdo&repo=wtf-forms&type=fork&count=true" allowtransparency="true" frameborder="0" scrolling="0" width="98" height="20"></iframe>
</li>
</ul>
<ul class="quick-links">
<li class="follow-btn">
<a href="https://twitter.com/mdo/" class="twitter-follow-button" data-link-color="#0069D6" data-show-count="true">Follow @mdo</a>
</li>
<li class="tweet-btn">
<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://wtfforms.com/" data-count="horizontal" data-via="mdo">Tweet</a>
</li>
</ul>
</footer>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</body>
</html>