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

              
                <h1>Vertical Centering with CSS</h1>

<section id="vertical-align">
	<h2>Vertical-Align <small>using display: table</small></h2>
	<div id="parent">
		<div id="child">Vertical-Align</div>
	</div>
</section>

<section id="line-height">
	<h2>Line-Height Method</h2>
	<div id="parent">
		<div id="child">Line-Height</div>
	</div>
</section>

<section id="absolute-position">
	<h2>Absolute Position Method</h2>
	<div id="parent">
		<div id="child">Absolute Position</div>
	</div>
</section>

<section id="equal-padding">
	<h2>Equal Top/Bottom Padding Method</h2>
	<div id="parent">
		<div id="child">Equal Padding</div>
	</div>
</section>

<section id="vertical-align-alt">
	<h2>Vertical-Align <small>using display: table</small></h2>
	<div id="parent">
		<div id="child">Vertical-Align</div>
		<h3>Title</h3>
		<p>More content that will stretch the centered content as it extends the bounding boxes further and further down.</p>
	</div>
</section>
              
            
!

CSS

              
                /* ==== Source: http://blog.themeforest.net/tutorials/vertical-centering-with-css/
   ==== Source: http://www.student.oulu.fi/~laurirai/www/css/middle/
   ==== Source: http://www.vanseodesign.com/css/vertical-centering/ */


#vertical-align {
/* ==== May not work in IE9> */
	#parent {
		height: 100px;
		display: table;
		width: 100%;
	}
	#child {
		height: 100%;
		display: inline-block; /* to fix IE issues */
		display: table-cell;
		vertical-align: middle;
		text-align: center;
	}
}

#vertical-align-alt {
/* ==== May not work in IE9> */
	#parent {
		min-height: 100px;
		display: table;
		width: 100%;
		h3, p {
			margin: .5em 1em;
		}
	}
	#child {
		height: 100%;
		display: inline-block; /* to fix IE issues */
		display: table-cell;
		vertical-align: middle;
		text-align: center;
		width: 55px;

	}
}

#line-height {
/* ==== Line-height must be larger than the font-size that’s been set */
	#child {
		line-height: 100px;
		text-align: center;
	}
}

#absolute-position {
/* ==== I hate this messy method */
	#parent {
		height: 100px;
		position: relative;
	}
	#child {
		position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		width: 50%;
		height: 30%;
		margin: auto;
		text-align: center;
	}
}

#equal-padding {
/* ==== */
	#parent {
		padding: 5% 0;
	}
	#child {
		padding: 10% 0;
		text-align: center;
	}
}


/* STOP HERE. The rest of this CSS is for style purposes only and is not needed for the demo to function.
              (but be sure to substitue out the LESS variables/mixins I used above)
   ---------------------------------------------------------------------------------------------------- */

/* =VARIABLES (LESS @variables do not get compiled into the final CSS file)
   ---------------------------------------------------------------------------------------------------- */
@base-background:      #fffaef; /*cream*/
@base-text:            #4f4351; /*purple/grey*/

@color-subtitles:      #9a8864; /*mud*/
@color-highlight:      #e9e59b; /*lime*/
@color-dark:	       #080c3c; /*midnight*/

@color-button:         #f2f2f0; /*grey*/
@color-button-text:    darken(@color-button, 50%); /*grey*/
@color-button-border:  darken(@color-button, 10%); /*grey*/
@color-button-on:      #ffa640; /*orange*/


/* =MIXINS
   ---------------------------------------------------------------------------------------------------- */
// Border Radius
.border-radius(@radius) {
  -webkit-border-radius: @radius;
     -moz-border-radius: @radius;
          border-radius: @radius;
}

// Drop shadows
.box-shadow(@shadow) {
  -webkit-box-shadow: @shadow;
     -moz-box-shadow: @shadow;
          box-shadow: @shadow;
}

// Opacity
.opacity(@opacity) {
	opacity: @opacity / 100;
	filter: ~"alpha(opacity=@{opacity})";
}


/* =BASE STYLES
   ---------------------------------------------------------------------------------------------------- */
/* =BASE STYLES
   ---------------------------------------------------------------------------------------------------- */
body {
	background: @base-background;
	color: @base-text;
	font-family: Arial, Helvetica, sans-serif;
	margin: 5em 2em;
}

h1, h2 {
	color: @base-text;
	letter-spacing: -.05em;
	text-align: center;
	text-shadow: 0 1px 2px fade(lighten(@base-background, 50%), 50%);
}
h1 {
	background: fade(@base-text, 10%);
	border-bottom: 1px solid fade(@base-background, 90%);
	outline: 1px solid fade(@base-text, 20%);
	margin: 0 auto;
	padding: .5em;
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
}

h3, h4, h5 { color: @base-text; }

small, hr {
	display: block;
	margin: 1em 0;
	.opacity(50);
}

section {
	background: fade(@color-highlight, 20%);
	border: 1px solid fade(@color-highlight, 50%);
	.border-radius(4px);
	.box-shadow(0 1px 2px fade(@color-subtitles, 50%));
	display: block;
	float: left;
	margin: 1em;
	min-height: 200px;
	padding: 1em;
	position: relative;
	width: 20%;
	h2 {
		line-height: 1;
		margin: 0 0 1em 0;
		min-height: 2.5em;
		padding: 0;
		small {
			font-size: 70%;
			line-height: 1;
			margin: 0;
			padding: 0;
		}
	}
	div {
		background: fade(@color-subtitles, 10%);
		.border-radius(4px);
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console