Skip to content

Commit

Permalink
Resolve una#28: Add pure-CSS Float Label demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tonystar committed Oct 15, 2016
1 parent 18a8965 commit 9296548
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
4 changes: 4 additions & 0 deletions comparisons/forms/float_labels/caniuse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Placeholder Attribute: http://caniuse.com/#feat=input-placeholder
Placeholder Shown: http://caniuse.com/#feat=css-placeholder-shown
Not Selector: http://caniuse.com/#feat=css-sel2
Adjacent Sibling Selector: http://caniuse.com/#feat=css-sel2
1 change: 1 addition & 0 deletions comparisons/forms/float_labels/codepen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p data-height="400" data-theme-id="light" data-slug-hash="JRLaKw" data-default-tab="result" data-user="tonystar" data-embed-version="2" class="codepen">See the Pen <a href="https://codepen.io/tonystar/pen/JRLaKw/">Float Label CSS-only</a> by Anton Staroverov (<a href="http://codepen.io/tonystar">@tonystar</a>) on <a href="http://codepen.io">CodePen</a>.</p>
20 changes: 20 additions & 0 deletions comparisons/forms/float_labels/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<fieldset>
<legend>Sign up</legend>

<div class="has-float-label">
<input id="first" type="text" placeholder="First Last"/>
<label for="first">Name</label>
</div>

<div class="has-float-label">
<input id="email" type="email" placeholder="[email protected]"/>
<label for="email">Email</label>
</div>

<div class="has-float-label">
<input id="password" type="password" placeholder="••••••••"/>
<label for="password">Password</label>
</div>

<button>Sign up</button>
</fieldset>
3 changes: 3 additions & 0 deletions comparisons/forms/float_labels/resources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Micro-Library by Anton Staroverov: https://github.com/tonystar/float-label-css
Plugin for Bootstrap: https://github.com/tonystar/bootstrap-float-label
Float Label Pattern: http://mds.is/float-label-pattern/
40 changes: 40 additions & 0 deletions comparisons/forms/float_labels/scss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.has-float-label {
position: relative;

// Minimize label and move on top:
label {
position: absolute;
left: 0;
top: 0;
cursor: text;
font-size: 75%;
opacity: 1;
transition: all .2s;
}

input {
padding-top: 1em;

&::-webkit-input-placeholder {
opacity: 1;
transition: all .2s;
}

// Replace placeholder by sibling label
// when no data and not in focus:
&:placeholder-shown:not(:focus) {
// Non-supporting browsers don't see the code
// below. But everything is ok since the label
// is minimized by default. MAGIC!

&::-webkit-input-placeholder {
opacity: 0;
}
+ label {
top: .25em;
font-size: 150%;
opacity: .5;
}
}
}
}

0 comments on commit 9296548

Please sign in to comment.