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

              
                <div class="wrapper">
  <h3>Method 1: Using flex</h3>
  <div class="common center1">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
  <h3>Method 2: Using Grid(place-items)</h3>
  <div class="common center2">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 3: Using Grid(align and justify self)</h3>
  <div class="common center3">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 4: Using CSS Positioning and CSS transform(translate)</h3>
  <div class="common center4">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 5: Using CSS Margin</h3>
  <div class="common center5">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 6: Using CSS Positioning</h3>
  <div class="common center6">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 7: Using CSS Table(with margin)</h3>
  <div class="common center7">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
   <h3>Method 8: Using CSS Table(with display: inline-block)</h3>
  <div class="common center8">
    <div class="parent">
      <div class="child center-text">Center Me<span>🐣</span></div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-color: #ffc4a3;
  display: flex;
  justify-content: center;
  margin-top: 50px;
  font-family: 'Merriweather Sans', sans-serif;
}



* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.wrapper {
     display: flex;
    flex-direction: column;
    align-items: center;
}

h3 {
  margin-bottom: 10px;
  width: 420px;
  color: #303960;
  text-align: center;
}

.center-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 120px;
  height: 100px;
  background-color: #f96d80;
  border: 5px solid #303960;
  padding: 10px;
}
.center-text span {
  font-size: 25px;
}

.common {
  width: 350px;
  height: 450px;
  border: 8px solid #bb596b;
  margin-bottom: 25px;
}

/*-------------------------------  */
/* Flex Properties */

.center1 .parent {
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* ------------------------------ */
/* CSS Grid */

.center2 .parent {
  height: 100%;
  display: grid;
  place-items: center;
}

.center3 .parent {
  height: 100%;
  display: grid;
}

.center3 .child {
  align-self: center;
  justify-self: center;
}


/* ------------------------------ */
/* CSS Positioning and translate properties */

.center4 .parent {
  position: relative;
  height: 100%;
}

.center4 .child {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%)
}


/* ------------------------------ */
/* CSS Margins */

.center5 .parent {
  height: 100%;
}

.center5 .child {
  margin: 0 auto;
  margin-top: 50%;
}

/* ------------------------------ */
/* CSS Positioning */

.center6 .parent {
  height: 100%;
  position: relative;
}

.center6 .child {
  position: absolute;
  top: 0;
  left: 0;
  right:0;
  bottom: 0;
  margin: auto;
}

/* In firefox, in place of left/right/top/bottom - we can use inset  */


/* ------------------------------ */
/* Display - Table Properties */

.center7 {
  display: table;
}

.center7 .parent {
  height: 100%;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

.center7 .child {
  margin: 0 auto;
}

.center8 {
  display: table;
}

.center8 .parent {
  height: 100%;
  display: table-cell;
  text-align: center;
  vertical-align: middle;
}

.center8 .child {
  display: inline-block
}
              
            
!

JS

              
                
              
            
!
999px

Console