cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              %section
  .inner
    %h1 Hero section
    %p Resize the browser window to see the section height and content position update.

%section
  .inner
    %h2 Next section
    
%section
  .inner
    %h2 Third section
            
          
!
            
              body
  font-family: Helvetica, sans-serif

body, html
  height: 100%

body, h1, h2
  margin: 0
  padding: 0

h1, h2, p
  padding: 0 40px
  
section:nth-child(odd)
  background-color: #eee
  
section
  position: relative
  height: 100%
   
.inner
  left: 0
  max-width: 960px
  margin: 0 auto
  position: absolute
  right: 0
  top: 50%
  -webkit-transform: translateY(-50%)
  -moz-transform: translateY(-50%)
  transform: translateY(-50%)
            
          
!
            
              class browserHeightSection

  constructor: ->
    @increaseSectionHeight()
    resizeSection = debounce( =>
      @increaseSectionHeight()
    , 50)

    window.addEventListener "resize", resizeSection

  increaseSectionHeight: =>
    windowHeight = window.innerHeight || document.documentElement.clientHeight

    $('section').height(windowHeight).each () ->
      section = $(this).find('.inner')
      sectionTopMargin = (section.height() / 2) * -1 + 'px'
      section.css('margin-top', sectionTopMargin)

  debounce = (func, wait, immediate) ->
    timeout = undefined
    ->
      context = this
      args = arguments
      later = ->
        timeout = null
        func.apply context, args  unless immediate
        return

      callNow = immediate and not timeout
      clearTimeout timeout
      timeout = setTimeout(later, wait)
      func.apply context, args  if callNow
      return

$ ->
  if $('.csstransforms').length == 0
    new browserHeightSection()

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console