Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                
<header>
  <h2><code>position: static;</code></h2>
  <p>Nothing to see here, folks. Normal default document flow.</p>
</header>

<section class='static'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>



<header>
  <h2><code>position: sticky;</code></h2>
  <p>Can stay in frame by "sticking" around when scrolled past. Note: you must set place to stick such as <code>top: 0px;</code> or it won't know what to stick to.</p>
</header>

<section class='sticky'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>



<header>
  <h2><code>position: relative;</code></h2>
  <p>Position based on it's natural place in the document flow. It will hold it's place in the flow / but visually move.</p>
  <p>Also, this will team up with absolute positioning.</p>
</header>

<section class='relative'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>



<header>
  <h2><code>position: absolute;</code></h2>
  <p>This will position things based on the closest <em>relative</em>(ly positioned) parent. It will be removed from the document flow.</p>
</header>

<section class='absolute'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>



<header>
  <h2><code>position: fixed;</code></h2>
  <p>Based on the viewport bounderies. It will be removed from the document flow.</p>
  
  <p>You can also change the boundery from the viewport by adding a property like transform to another element and have it behave as the parent context.</p>
</header>

<section class='fixed'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>



<header>
  <h2><code>transform: translate(x, y);</code></h2>
  <p>Translate: ... like relative - but / easier on the rendering engine and smooth to animate! (plus transform can do way more than just move on an X/Y axis)</p>
</header>

<section class='translate'>
  <div class='a'></div>
  <div class='b'></div>
  <div class='c'></div>
</section>

              
            
!

CSS

              
                /* SETUP */
* { 
  box-sizing: border-box; 
}


.b { /* we're highligting this one for some reason */
  border: 2px solid black;
}


.sticky .b {
  position: sticky;
  top: 0;
}

.relative .b {
  top: 20px;
  left: 20px;
}


.absolute {
  position: relative;
}

.absolute .b {
  position: absolute;
  right: -10px;
  bottom: 50px;
}


.fixed .b {
  position: fixed;
  bottom: 0;
  right: 0;
}




/* not really the 'position' property - but you can use it to position things! */
.translate .b {
  transform: translate(20px, 20px);
  transition: 0.5s ease-in-out;
  z-index: 2;
}

.translate:hover .b {
  transform: translate(50px, 50px) scale(1.2) rotate(-370deg);
  box-shadow: 0 3px 10px 0 rgba(0,0,0,.7);
}

















































/* FOR PRESENTATION PURPOSES ONLY */

header {
  margin-top: 60px;
}

body {
  padding: 40px 30px 200px;
}

p {
  max-width: 70ch;
}

div {
  display: inline-block;
  width: 80px;
  height: 80px;
  background-color: lightgray;
}

section {
  min-height: 340px;
  border: 1px solid lightgray;
}

.sticky {
  min-height: 500px;
  /* to make sure it's visibly obvious what is happening */
}

/* TRYING to keep the markup clean and digestable, so - using some tricks to get the letters of the boxes in place  */
div {
  position: relative;
  font-family: sans-serif;
  font-size: 30px;
  color: rgba(0,0,0,.3);
/*   border-radius: 10px; */
  opacity: .9;
}

div:after {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

div.a:after {
  content: "a";
}

div.b:after {
  content: "b";
}

div.c:after {
  content: "c";
}

div.a {
  background-color: var(--pe-orange-light);
}

div.b {
  background-color: var(--pe-orange);
}

div.c {
  background-color: var(--pe-orange-dark);
}


.sticky div.a {
  background-color: var(--pe-green-light);
}
.sticky div.b {
  background-color: var(--pe-green);
}
.sticky div.c {
  background-color: var(--pe-green-dark);
}


.relative div.a {
  background-color: var(--pe-blue-light);
}
.relative div.b {
  background-color: var(--pe-blue);
}
.relative div.c {
  background-color: var(--pe-blue-dark);
}


.absolute div.a {
  background-color: var(--pe-red-light);
}
.absolute div.b {
  background-color: var(--pe-red);
}
.absolute div.c {
  background-color: var(--pe-red-dark);
}


.fixed div.a {
  background-color: var(--pe-yellow-light)
}
.fixed div.b {
  background-color: var(--pe-yellow)
}
.fixed div.c {
  background-color: var(--pe-yellow-dark)
}


.translate div.a {
  background-color: var(--pe-purple-light);
}
.translate div.b {
  background-color: var(--pe-purple);
}
.translate div.c {
  background-color: var(--pe-purple-dark);
}

              
            
!

JS

              
                
              
            
!
999px

Console