cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <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>
            
          
!
            
              * {
  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;
}
            
          
!
            
              // 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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console