cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

            
              <header>  
 <h1>Vertical Centering: Everything You Need to Know</h1>
    <a href="http://webdesignerwall.com/tutorials/css-vertical-centering-everything-need-know" target="_blank">View Tutorial</a>
</header>

<div class="intro">*Hover over the text to see how each method centers it within its parent.</div>

<div class="container">
  <h2>absolute</h2>
  <div class="item one"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
  <h2>table</h2>
  <div class="item two"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
  <h2>transform</h2>
  <div class="item three"><p>To be able under all circumstances to practice five things constitutes perfect virtue; these five things are gravity, generosity of soul, sincerity, earnestness and kindness.</p></div>
</div>
<div class="container">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
 <h2>line height</h2>
  <div class="item four"><i class="fa fa-css3" aria-hidden="true"></i></div>
</div>
<div class="container">
  <h2>padding</h2>
  <div class="item five"><p>When I walk along with two others, from at least one I will be able to learn.</p></div>
</div>
<div class="container">
  <h2>flexbox</h2>
  <div class="item six"><p>To be able under all circumstances to practice six things constitutes perfect virtue; these six things are gravity, generosity of soul, sincerity, earnestness, kindness and vertical alignment.</p><a href="#"> Link </a></div>
</div>
<div class="container">
  <h2>Combined Elements</h2>
  <div class="item with-image">
    <figure><img src="https://24.media.tumblr.com/1d8dd5361a12d9c51077764adf9a1158/tumblr_mvdci7SSY51r4mh0bo1_r1_500.gif"></figure>
    <div class="content"><h3>Maybe A Title</h3><p>When I walk along with two others, from at least one I will be able to learn.</p></div>
  </div> 
</div>

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

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  background: linear-gradient(90deg, #f598a8, #f6edb2);
  align-items: center;
  height: 100vh;
  position: relative;
  font-family: 'source sans pro', sans-serif;
}
.intro{
  font-size: 1.2rem;
  display: block;
  text-align: center;
  color: #555;
  font-style: italic;
}
.container {
  width: 80vw;
  margin: 2vw auto;
  border: 0.25rem solid rgba(255, 255, 255, 0.1);
  padding: 2vw;
  transition: border 0.25s ease;
}
.container h2{
    padding: 0 0 0 1rem;
    opacity: 0.25;
    font-size: 2rem;
    transition: opacity 0.25s ease;
 }
.item {
  position: relative;
  background-color: white;
  margin: 1rem;
  padding: 1rem;
  min-height: 33vh;
  overflow: hidden;
  font-size: 1.25rem;
  color: rgba(0, 0, 0, 0.25);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
  transition: all 0.25s ease;
}
.item:hover {
    color: rgba(0, 0, 0, 0.75);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
}
.item p{
  margin: 0;
  padding: 0;
  border: 0.25rem dashed rgba(239, 230, 195, 0.1);
}
.item:hover p {
   border: 0.25rem dashed rgba(239, 230, 195, 0.75);
}
.item:hover p:after {
    opacity: 0.5;
}
/* Positioning */

/* Absolute */

.one p{
    position:absolute;
    top: 33%;
    right:0;
    bottom:0;
    left:0;
    margin: auto;
    padding: 0 2rem;
}
/* table */
.two{
  display: table;
}
.two p{
  display: table-cell;
  vertical-align: middle;
}
/* translate */
.three{
  height: 33vh;
}
.three p{
    position: relative;
    top: 50%;
    -webkit-transform: translateY(-50%);
    -ms-transform: translateY(-50%);
    transform: translateY(-50%);
}
/* line height */
.four{
  width: 4rem;
  height: 4rem;
  border-radius: 100%;
  margin: 0 auto;
  padding: 0;
  min-height: auto;
  line-height: 4rem;
  text-align: center;
}


/* padding */
.five{
  padding: 16.5vh 8.25vh;
  text-align: center;
}


/* flexbox */
.six{
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* flexbox with image */
.with-image{
  height: auto;
  display: flex;
  flex-direction: row;
}
.with-image img, .with-image .content{
  width: calc(50%);
}
.with-image figure img{
  width: 100%;
  height: auto;
  object-fit: contain;
}
.content{
  margin: 0 2rem;
  align-self: center;
}


/* General style */
a{
    font-size: .8rem;
    text-decoration: none;
    color: #999;
    text-transform: uppercase;
    font-family: sans-serif;
}

header{
  width: 100%;
  display: block;
  background: #FFF;
  height: 40px;
  margin-bottom: 4%;
  color: #ccc;
  font-family: sans-serif;
  font-weight: bold;
  box-shadow: 0px 2px 0px 0px rgba(125,121,125,0.3);
  overflow: hidden;
}
header h1, header a{
  display: inline-block;
  font-size: .8rem;
  margin: auto 10px;
  line-height: 40px;

}
header h1{
    text-transform: uppercase;
    letter-spacing: 1px;
}
header a{
  text-decoration: none;
  background-color: #eee;
  color: #999;
  padding: 0 20px;
  transition: all ease-in-out .3s;
}
header a:hover{
  background-color: #93dfec;
  color: #eee;
  margin-left: -3px;
}



@media screen and (max-width: 667px){
  .item:not(.four){
    min-height: 50vh;
  }
  .item span{
    font-size: 4vw;
  }
  .with-image{
    flex-direction: column;
    justify-content: center;
  }
 .with-image img, .with-image .content{
  text-align: center;
  width: calc(100%);
  height: calc(100%);
}
            
          
!
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