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.

            
              <div class="container">
  <!-- for sections with fixed background-->
  <div class="fixed-bg bg-1 parent-vcenter">
    <div class="child-vcenter">
      <h1>Be the best</h1>
      #fixed
    </div>
  </div>
  <div class="parent-vcenter">
    <div class="child-vcenter pad-me">
      <h1 style="margin:0">Default scrolling here</h1>
      <br />
      #scroll
    </div>
  </div>
  <div class="fixed-bg bg-2 pad-me">
    <div>
      <h1>Amazing isn't it?</h1>
    </div>
  </div>
</div>
            
          
!
            
              * {
  box-sizing: border-box;
}

html, body, .container {
  /*important*/
  height: 100%;
} 

.fixed-bg {
  /*min-height: 100%;*/
  background-size: cover;
  background-attachment: fixed;
  background-repeat: no-repet;
  background-position: center center;
  height: 100vh; 
  color: #fff;
  /*to vertically align the content inside, a definite height should be set on the parent. min-height doesn't work.*/
}

.parent-vcenter {
  text-align: center;
}

 /*ghost element for vertical centering*/
.parent-vcenter:before {
  content: '';
  display: inline-block;
  height: 100%;
  vertical-align: middle;
  margin-right: -0.25em; /*adjusts for spacing*/
}

/*content to be vertically centered*/
.child-vcenter {
  /*vertically center*/
  display: inline-block;
  vertical-align: middle;
}

.fixed-bg.bg-1 {
  background-image: url("https://ununsplash.imgix.net/uploads/14115120538776712c565/a699942a?fit=crop&fm=jpg&q=75&w=1050");
}

.fixed-bg.bg-2 {
  background-image: url("https://ununsplash.imgix.net/photo-1416949929422-a1d9c8fe84af?fit=crop&fm=jpg&h=700&q=75&w=1050");
  /*reset height to auto if you want the content to determine the height. just use padding though.*/
  height: auto;
}

.scrolling-bg {
  /*min-height: 100%;*/
  height: 300px;
}

h1 {
  font-size: 10vh;
}

h2 {
  font-size: 1.5em;
}

.pad-me {
  padding: 20px;
}



            
          
!
            
              /*
Alternate Fixed & Scroll Backgrounds by Codyhouse
https://codyhouse.co/gem/alternate-fixed-scroll-backgrounds/
*/
            
          
!
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