startv

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
via CSS Lint

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
via JS Hint

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              
<h3>DEMONSTRATING THE DIFFERENCE BETWEEN RELATIVE POSITIONING AND POSITIVE/NEGATIVE MARGINS</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>


            
          
!

CSS

            
              * {
  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;
}
  
            
          
!

JS

            
              
            
          
!
999px
Loading ..................

Console