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

              
                <p><a href="https://codepen.io/ricardozea/pen/c4e27f1e74542618d73e21f7c2276272?editors=0100" target="_blank">There's an easier way of doing this using Grid.</a></p>
<hr>
<h1> How to vertically align an image inside div using Flexbox</h1>
<div class="frame">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9988/hand-pointing.png">
</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 {
    display: flex;
    /**
    Uncomment 'justify-content' below to center horizontally.
    ✪ Read below for a better way to center vertically and horizontally.
    **/

    /*justify-content: center;*/
    align-items: center;
}

img {
    height: auto;

    /**
    ✪ To center this image both vertically and horizontally,
    in the .frame rule above comment the 'justify-content' 
    and 'align-items' declarations,
    then  uncomment 'margin: auto;' below. 
    **/

    /*margin: auto;*/
}








/* Styles NOT needed for demo */
.frame {
    max-width: 900px;
    height: 200px;
    margin: auto;
    background: rgba(black, .3);
    border-radius: 3px;
    box-shadow: 0 2px 5px rgba(black, .1);
}
p {
    max-width: 900px;
    margin: 20px auto 0;
}
img {
    width: 150px;
}

/*  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