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

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>Vertically align an image inside a DIV using CSS Grid and the <code>place-content</code> shorthand (easier than with&nbsp;Flexbox)</h1>
<div class="ctnr frame-image-grid">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9988/hand-pointing.png">
</div>
<div class="ctnr frame-text-grid">
    <h2>Align text using CSS Grid and <code>place-content</code></h2>
    <p>Only two lines are needed to center vertically and horizontally.</p>
</div>
<div class="ctnr frame-text-flexbox">
    <h2>Align text using Flexbox and <code>place-content</code></h2>
    <p>An extra <code>flex-direction: column;</code> declaration is needed to center vertically and horizontally if using Flexbox.</p>
</div>
<p>Demo for this question on Stack Overflow: <a href="http://stackoverflow.com/questions/7273338/how-to-vertically-align-an-image-inside-div/34518335#34518335" target="_blank">How to vertically align an image inside div</a></p>
              
            
!

CSS

              
                .frame-image-grid {
    display: grid;
    place-content: center;
}

.frame-text-grid {
    display: grid;
    place-content: center;
    /**
    ✪ "place-content" is the shorthand for "align-content" and "justify-content".
    
    ✪ The "place-content" shorthand requires two values, the first one is for
    "align-content" and the second one for "justify-content". If only one value is 
    present (like in this demo), then that single value is applied
    to both directions.
    
    ✪ Comment the "place-content: center;" declaration above to see how the elements
    are spread along the height of the container.
    **/
}

.frame-text-flexbox {
    display: flex;
    flex-direction: column;
    place-content: center;
    
    /**
    ✪ The "place-content" shorthand can also be used with Flexbox,
    but we would need to add a "flex-direction" property so things
    remain in one column.
    
    ✪ Comment the "flex-direction: column;" declaration above to
    see how the alignment breaks.
    **/
}








/* Styles NOT needed for demo */
.ctnr {
    max-width: 900px;
    height: 200px;
    margin: 1em auto; 
    background: rgba(black, .3);
    border-radius: 3px;
    box-shadow: 0 2px 5px rgba(black, .1); 
}
p {
    max-width: 900px;
    margin: 20px auto 0; 
}
.ctnr * { margin: 0; }
.ctnr h2 { margin-bottom: 10px;}
img { width: 150px; }
h1, h2 { text-align: center; }
h1 code {
    font-size: 1em;
    color: white;
    text-transform: none;
    background: none;
    box-shadow: none;
}
h2 {
    background: rgba(black, .3);
    code { 
        font-size: 1em;
        color: white;
    }
}


/*  New tab icon
    https://stackoverflow.com/questions/1899772/new-window-icon-for-web-accessibility/51700279#51700279 
*/
.new-tab:after {
    display: inline-block;
    content: "⇱";
    position: relative;
    top: -5px;
    margin-left: 2px;
    transform: rotate(90deg);
}
              
            
!

JS

              
                /* 
    Script to improve UX of links that open a new tab
    https://stackoverflow.com/questions/1899772/new-window-icon-for-web-accessibility/51700279#51700279
*/
var tlinks = document.querySelectorAll("a[target=_blank]");
for (var x = 0; x < tlinks.length; x++) {
    tlinks[x].title = "Opens in new tab";
    var currentClass = tlinks[x].getAttribute("class");
    if (currentClass == null) currentClass = "";
    tlinks[x].setAttribute("class", currentClass + " new-tab");
}
              
            
!
999px

Console