<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Floating label pattern demo</title>
</head>
<body>
<h1>Floating labels demo</h1>
<p>By <a href="https://twitter.com/thatemil">@thatemil</a></p>
<form action="">
<div class="field">
<input type="text" name="fullname" id="fullname" placeholder="Jane Appleseed">
<label for="fullname">Name</label>
</div>
<div class="field">
<input type="email" name="email" id="email" placeholder="jane.appleseed@example.com">
<label for="email">Email</label>
</div>
</form>
<p>Will probably work crap in lots of browsers. Works OK in recent Chrome, WebKit/Safari. See the <a href="http://thatemil.com/blog/2016/01/23/floating-label-no-js-pure-css/">accompanying blog post</a></p>
</body>
</html>
body {
font-family: Avenir Next, Avenir, SegoeUI, sans-serif;
}
form {
margin: 2em 0;
}
/**
* Make the field a flex-container, reverse the order so label is on top.
*/
.field {
display: flex;
flex-flow: column-reverse;
margin-bottom: 1em;
}
/**
* Add a transition to the label and input.
* I'm not even sure that touch-action: manipulation works on
* inputs, but hey, it's new and cool and could remove the
* pesky delay.
*/
label, input {
transition: all 0.2s;
touch-action: manipulation;
}
input {
font-size: 1.5em;
border: 0;
border-bottom: 1px solid #ccc;
font-family: inherit;
appearance: none;
border-radius: 0;
padding: 0;
cursor: text;
}
input:focus {
outline: 0;
border-bottom: 1px solid #666;
}
/**
* Translate down and scale the label up to cover the placeholder.
* Also make sure the label is only on one row, at max 2/3rds of the
* field—to make sure it scales properly and doesn't wrap.
*/
label {
text-transform: uppercase;
letter-spacing: 0.05em;
cursor: text;
max-width: 66.66%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transform-origin: left bottom;
transform: translate(0, 2.125rem) scale(1.5);
}
/**
* By default, the placeholder should be transparent. Also, it should
* inherit the transition.
*/
::input-placeholder {
opacity: 0;
transition: inherit;
}
/**
* Show the placeholder when the input is focused.
*/
input:focus::input-placeholder {
opacity: 1;
}
/**
* When the element is focused, remove the label transform.
* Also, do this when the placeholder is _not_ shown, i.e. when
* there's something in the input at all.
*/
input:not(:placeholder-shown) + label,
input:focus + label {
transform: translate(0, 0) scale(1);
cursor: pointer;
}
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |