Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="page-wrap">
  <h1>Polymer's Floating Label Input via CSS</h1>
  <form>
    <div class="styled-input">
      <input type="text" required />
      <label>Name</label>
      <span></span>
    </div>
    <div class="styled-input">
      <input type="email" required />
      <label>Email</label>
      <span></span>
    </div>
    <div class="styled-input">
      <input type="tel" required />
      <label>Phone</label>
      <span></span>
    </div>
    <div class="styled-input wide">
      <textarea required></textarea>
      <label>Message</label>
      <span></span>
    </div>
  </form>
</div>
              
            
!

CSS

              
                * {
  box-sizing: border-box;
}

body {
  background: #ecf0f1;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", "DejaVu Sans", Verdana, sans-serif;
}

.page-wrap{
  max-width: 75rem;
  margin: 0 auto;
}

h1 {
  color: #8e44ad;
  font-size: 1.5rem;
  letter-spacing: -1px;
  margin: 1.25rem 0;
}

// Effect Styles Start Here

%label-movement {
  // Move up, colorize and shrink
  font-size: 0.75em;
  color: #8e44ad;
  top: -2.25rem;
  transition: all 0.125s cubic-bezier(0.2, 0, 0.03, 1);
}

.styled-input {
  float: left;
  width: 33.3333%;
  margin: 2rem 0 1rem;
  position: relative;
  label {
    color: #999;
    padding: 1rem;
    position: absolute;
    top: 0;    
    left: 0;
    transition: all 0.25s cubic-bezier(0.2, 0, 0.03, 1);
    pointer-events: none;
  }
  &.wide {
    // Full width textarea fields
    width: 100%;
  }
}

input, textarea {
  padding: 1rem 1rem;
  border: 0; 
  width: 100%;
  font-size: 1rem;
  ~ span {
    // Border Effect
    display: block;
    width: 0;
    height: 3px;
    background: #8e44ad;
    position: absolute;
    bottom: 0;
    left: 0;
    transition: all 0.125s cubic-bezier(0.2, 0, 0.03, 1);
  }
  &:focus {
    // Trigger the effects
    outline: 0;
	  ~ label {
      // Move Label
      @extend %label-movement;
  	}
    ~ span {
      // Expand across
      width: 100%;
      transition: all 0.125s cubic-bezier(0.2, 0, 0.03, 1);
    }
	}
  &:valid ~ label/*, &.not-empty ~ label*/ {
    // Keep label above field after its filled out
    @extend %label-movement;
  }
}

textarea {
  // Mods needed for multiline inputs
  width: 100%;
  min-height: 15em;
}
              
            
!

JS

              
                // Update 7/7/14 - Looks like replacing the span with pseudo elements is out. No pseudo-elements on inputs and no parent selector 

// Update 7/11/14 - Added jQuery to add a class to inputs after they have a value to keep labels up even with invalid values (this and its corresponding scss are commented out)

/*

// Keep a label up even with invalid value
$( 'input' ).on( 'blur', function() {

  var $this = $( this );
  
  if ( $this.val() !== "" ) {
  
    $this.addClass( 'not-empty' );
    
  } else {
  
    $this.removeClass( 'not-empty' );
    
  }
  
} );

*/
              
            
!
999px

Console