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 includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                .row(ng-app="PlaceholderDemoApp" ng-controller="test")
  .form-group.container
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Default")
    .col-lg-4.form-group.has-error
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Error State, same as 1st and 3rd inputs values. This one is extremely long and is overly so just to show what would happen.")
    .col-lg-4.form-group.has-warning
      input.form-control.better-placeholder(type="password" ng-model="text1" placeholder="Password Text")
  .form-group.container
    .col-lg-4.form-group.has-success
      input.form-control.better-placeholder(type="email" ng-model="text2" placeholder="Email Text")
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="email" ng-model="text2" ng-placeholder="testplaceholder")
    .col-lg-4.form-group
      input.form-control.better-placeholder(type="email" placeholder="Not Ng-Model" value="yay")
    .col-lg-12.form-group
      input.form-control.better-placeholder(type="text" ng-model="text1" placeholder="Error State, same as 1st and 3rd inputs values. This one is extremely long and is overly so just to show what would happen. Even in extreme circumstances that are realistically a bit stupid.")
              
            
!

CSS

              
                @import "nib"

.col-lg-4
  position: relative
.better-placeholder
  transition: all 0.5s ease
  &::placeholder
    display: none
    opacity: 0
  &.better-placeholder-active
    padding: 18px 12px 6px 12px
    height: auto
.has-error .better-placeholder-text
  color: #A94442
  &.active
    color: #A94442
.has-success .better-placeholder-text
  color: #3C763D
  &.active
    color: #3C763D
.has-warning .better-placeholder-text
  color: #8A6D3B
  &.active
    color: #8A6D3B
.better-placeholder-text
  transition: all 0.5s ease
  position: absolute
  color: #888
  top: 2px
  margin-left: 12px
  line-height: 20px
  height: 20px
  transform-origin: 0 0
  max-width: 85% /* You have to fiddle with this and it .active replacement depending on size of field */
  margin-right: 12px
  white-space: nowrap
  overflow: hidden
  text-overflow: ellipsis
  &.active
    max-width: 110%
    color: #428bca
    visibility: visible
    transform: scale(.8)
    transform-origin: 0 0
    top: -2px

.row
  margin-top: 40px
              
            
!

JS

              
                angular.module('PlaceholderDemoApp', [])
.directive 'betterPlaceholder', ->
	restrict: 'C'
	require: '?ngModel'
	scope: {}
	link: (scope, element, attrs, ngModel) ->
		isEmpty = (value= if ngModel? then ngModel.$viewValue else element.val()) -> (ngModel? and ngModel.$isEmpty value) or (not ngModel? and (not value or value is ''))
		if attrs.ngPlaceholder?
			scope.placeholder = scope.$parent.$eval attrs.ngPlaceholder
			element.attr 'placeholder', scope.placeholder
			scope.$parent.$watch attrs.ngPlaceholder, (val) ->
				element.attr 'placeholder', val
				placeholder.html val
		else if attrs.placeholder? and attrs.placeholder isnt '' then scope.placeholder = attrs.placeholder
		else throw "better-placeholder requires an ng-placeholder or placeholder attribute"
		
		placeholder = angular.element "<span class='help-block better-placeholder-text'>#{scope.placeholder}</span>"
		element.after placeholder
		placeholder.on 'click', -> element[0].focus()
		
		activate = ->
			element.addClass 'better-placeholder-active'
			placeholder.addClass 'active'
		deactivate = ->
			if isEmpty()
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
		
		# catch changes from the DOM
		element.on 'focus', activate
		element.on 'blur', deactivate
		element.on 'change', ->
			if isEmpty()
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
			else
				element.addClass 'better-placeholder-active'
				placeholder.addClass 'active'
		if ngModel? then ngModel.$formatters.push (value) ->
			if isEmpty value
				element.removeClass 'better-placeholder-active'
				placeholder.removeClass 'active'
			else
				element.addClass 'better-placeholder-active'
				placeholder.addClass 'active'
			value
		else if not isEmpty() then activate()
.controller 'test', ['$scope', ($scope) ->
	$scope.testplaceholder = "Set Via Scoped Var"
]
              
            
!
999px

Console