Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

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.

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

              
                <h1>Center to middle tricks</h1>
<p>:hover increases child size so you can verify how dynamic each method is.</p>
<h2>Trick 1: line-height</h2>
<div class="line-height">
  <span>1</span>
</div>
<p>Good: very dynamic. Bad: you need to know maximum height the child so you can set line-height accordingly. Firefox' vertical alignment is slightly off.</p>

<h2>Trick 2: display as table-cell</h2>
<div class="table">
  <span>2</span>
</div>
<p>Good: can center any kind of content to middle. Bad: parent needs extra wrapper element if you want to center it.</p>

<h2>Trick 3: absolute position</h2>
<div class="absolute">
  <span>3</span>
</div>
<p>Good: can break out of parent. Bad: can break out of parent and you need to define exact measurements of the child element so this is very limited.</p>

<h2>Trick 4: pseudo inline element</h2>
<div class="pseudo">
  <span>4</span>
</div>
<p>Good: fully dynamic, no line-height limitation. Bad: <code>font-size: 0;</code> can be troublesome. Lengthy code.</p>
              
            
!

CSS

              
                html {
  background: white;
}

body {
  background: #EEE;
  margin: 0 auto;
  padding: 1em;
  width: 30em;
}

h2 {
  background: #DDD;
  margin: .5em -.5em;
  padding: .5em;
}

/* shared styles */
div {
  background: green;
  height: 100px;
  width: 100px;
}

span {
  background: #CFC;
  box-shadow: 0 0 0 1px black;
  font-size: 32pt;
  height: 50px;
  width: 50px;
  text-align: left;
}

span:hover {
  padding: 20px;
}

/* minimum styles required for the effect */
.line-height {
  line-height: 100px;
  text-align: center;
}

.line-height span {
  display: inline-block;
  line-height: normal;
  vertical-align: middle;
}

.table {
  display: table-cell;
  vertical-align: middle;
}

.table span {
  display: block;
  margin: 0 auto;
}

.absolute {
  position: relative;
}

.absolute span {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -25px;
  margin-top: -25px;
}

.pseudo {
  font-size: 0;
  position: relative;
  text-align: center;
}

.pseudo:before {
  content: '';
  display: inline-block;
  height: 100%;
  width: 0;
  vertical-align: middle;
}

.pseudo span {
  display: inline-block;
  vertical-align: middle;
}
              
            
!

JS

              
                
              
            
!
999px

Console