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

              
                <h2>62.5em = 1000px = 100%</h2>

<section class="example1 clearfix">
    <p>The <code>.content</code> and the <code>.sidebar</code> with relative widths:</p>
    <div class="content"><b>70%</b></div>
    <div class="sidebar"><b>30%</b></div>
</section>

<section class="example2 clearfix">
    <p>The <code>.content</code> and the <code>.sidebar</code> with relative widths and relative gap:</p>
    <div class="content"><b>68%</b></div>
    <div class="sidebar"><b>30%</b></div>
</section>

<section class="example3 clearfix">
    <p class="widescreens">The <code>.content</code> with relative width while the <code>.sidebar</code> has fixed width:</p>
    <p class="narrowscreens"><code>.content</code> and <code>.sidebar</code> with relative widths:</p>
    <div class="content"><b><span>100%</span> &ndash; 20em</b><br> 20em = 320px = 32%</div>
    <div class="sidebar"><b>18.75em</b><br> 300px</div>
</section>

<section class="example4 clearfix">
    <p class="widescreens">The <code>.nav</code> and the <code>.sidebar</code> with fixed widths while the <code>.content</code> has relative width:</p>
    <p class="narrowscreens"><code>.nav</code>, <code>.content</code> and <code>.sidebar</code> with relative widths:</p>
    <div class="nav"><b>12.5em</b><br> 200px</div>  
  <div class="content"><b><span>100%</span> &ndash; 27.5em</b><br> 27.5em = 440px = 44%</div>
    <div class="sidebar"><b>12.5em</b><br> 200px</div>
</section>
              
            
!

CSS

              
                * {
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;
}
section {
    margin: 0 auto;
    max-width: 65em; /* 1040px */
    padding: 1.25em; /* 20px */
    width: 100%;
}
.content {
    float: left;
    width: 70%; /* 700px */
}
.sidebar {
    float: right;
    width: 30%; /* 300px */
}
.widescreens {
    display: block;
}
.narrowscreens {
    display: none;
}

/* EXAMPLE 2 */
.example2 .content {
    width: 68%; /* 680px */
}
.example2 .sidebar {
    width: 30%; /* 300px */
}

/* EXAMPLE 3 */
.example3 .content {
    width: 68%; /* 680px */
    width: -webkit-calc(100% - 20em); /* 100% ‒ 320px */
    width:    -moz-calc(100% - 20em);
    width:         calc(100% - 20em);
}
.example3 .sidebar {
    width: 30%; /* 300px */
    width: -webkit-calc(18.75em); /* 300px */
    width:    -moz-calc(18.75em);
    width:         calc(18.75em);
}
@media (max-width: 40em) { /* breakpoint for 400px */
    .example3 .widescreens {
        display: none;
    }
    .example3 .narrowscreens {
        display: block;
    }
    .example3 .content,
    .example3 .sidebar {
        float: none;
        position: relative;
        width: 100%;
    }
    .example3 .content:after,
    .example3 .sidebar:after {
        content: "100%";
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        line-height: 5em;
    }
    .example3 .sidebar:after {
        background-color: wheat;
    }
    .example3 .content:after {
        background-color: lightblue;
    }
    .example3 .sidebar {
        margin-top: 1.25em;
    }
}

/* EXAMPLE 4 */
.example4 .nav {
    float: left;
}
.example4 .content {
    margin-left: 1.25em; /* 20px */
    width: 56%; /* 560px */
    width: -webkit-calc(100% - 27.5em); /* 100% ‒ 440px */
    width:    -moz-calc(100% - 27.5em);
    width:         calc(100% - 27.5em);
}
.example4 .nav,
.example4 .sidebar {
    width: 20%; /* 200px */
    width: -webkit-calc(12.5em); /* 200px */
    width:    -moz-calc(12.5em);
    width:         calc(12.5em);
}
@media (max-width: 47em) { /* breakpoint for 470px */
    .example4 .widescreens {
        display: none;
    }
    .example4 .narrowscreens {
        display: block;
    }
    .example4 .content,
    .example4 .nav,
    .example4 .sidebar {
        float: none;
        position: relative;
        width: 100%;
    }
    .example4 .content:after,
    .example4 .nav:after,
    .example4 .sidebar:after {
        content: "100%";
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        line-height: 5em;
    }
    .example4 .nav:after,
    .example4 .sidebar:after {
        background-color: wheat;
    }
    .example4 .content:after {
        background-color: lightblue;
    }
    .example4 .content,
    .example4 .sidebar{
        margin-top: 1.25em;
        margin-left: 0;
    }
}







/* JUST FOR AESTHETICS */
body {
    background-color: lightgrey;
    color: #444;
    padding: 1.25em; /* 20px */
}
h2 {
    color: #666;
    margin: 0 0 .75em;
    text-align: center;
}
section {
    background-color: white;
    margin-bottom: 1.25em; /* 20px */
}
p {
    margin: 0 0 .5em;
}
code {
    background-color: lightgrey;
    margin: 0 .25em;
    padding: 0 .25em;
}
span {
    color: red;
}
.content,
.sidebar,
.nav {
    padding: 1.25em; /* 20px */
    text-align: center;
}
.content {
    background-color: lightblue;
}
.sidebar, .nav {
    background-color: wheat;
}
.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}
.clearfix:after {
    clear: both;
}
* {
    -webkit-transition: all .2s ease;
       -moz-transition: all .2s ease;
            transition: all .2s ease;
}
              
            
!

JS

              
                /*!

CSS CALC
  
62.5em = 1000px = 100%
1em = 16px = 1.6%
1.25em = 20px = 2%
...

Note 1: WebKit and Firefox currently require a browser prefix for calc()

Note 2: Be sure to use whitespace around operators so that they aren't construed as positive/negative notations.

CanIUse?
Not supported in Android less than 4.4 (KitKat) and Opera Mini (as of december/2013)

http://caniuse.com/#search=calc

***

Last update: 2013-12-18

- Added a fallback for browsers that doesn't support calc() yet.
Thanks to Osvaldas Valutis > http://osvaldas.info/imitating-calc-fallback-fixed-width-sidebar-in-responsive-layout

- Added media queries just for fun

*/
              
            
!
999px

Console