octocatstartv

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.

            
              
<h3>DEMONSTRATING THE DIFFERENCE BETWEEN RELATIVE POSITIONING AND POSITIVE/NEGATIVE MARGINS AND TRANSFORMS</h3>

<div class="page">
  
  <div class="wrapper">
    
    <div class="box">
      <p>This box is the specimen for comparison purposes.</p>
      <p>It is a grey box inside a blue box with a black border.</p>
    </div>
  </div>
  
  <div class="wrapper">
    <div class="box position">
      <p>This grey box is moved using relative positioning.</p>
      
      <p>The page remembers where it was and allocates that space as though the element was still there.</p>
      
      
    </div>
  </div>
  
  <div class="wrapper">
    <div class="box margin">
      <p>This grey box is moved using negative margin.</p>
      
      <p>See how the wrapper div has 'shrunk'?</p>
      
      &darr;  &darr;
    </div>
  </div>
  
  
    <div class="wrapper">
    <div class="box transform">
      <p>This grey box is moved using a transform.</p>
      
    <p>The page remembers where it was and allocates that space as though the element was still there.</p>
     
    </div>
  </div>
</div>


            
          
!
            
              * {
  box-sizing: border-box;
}

h3 {
  text-align:center;
}

.page {
  margin:0 auto;
  text-align: center;
}

.wrapper {
  border:5px solid black;
  margin:25px;
  display: inline-block;
  background:lightblue;
  vertical-align: top;
}

.box {
  width:200px;
  height:200px;
  background:lightgrey;
  border:1px solid grey;
  padding:10px;
  text-align:center;
}

.position {
  position:relative;
  top:-25px;
}

.margin {
  margin-top:-25px;
}

.transform {
  transform:translateY(-25px);
}
  
            
          
!
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