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

              
                <h1>Responsive Layout</h1>
<p>Inspired by Mike Riethmuller's <a href='https://codepen.io/MadeByMike/pen/YPJJYv?editors=110'>Pen</a>, this pen shows you how else the calc() function can be used.</p>
<p>In these examples, the green box is the variable one. Change the variables in the scss file.</p>
<h2>Positioning</h2>
<div class="box-position box1"></div>
<div class="box-position box2"></div>
<div class="box-position box3"></div>
<h2>Width</h2>
<div class="box-width box4"></div>
<div class="box-width box5"></div>
<div class="box-width box6"></div>
              
            
!

CSS

              
                $start-unit: 50px;
$end-unit: 400px;
$min-width: 400px;
$max-width: 800px;

$m: 100 * ($end-unit - $start-unit) / ($max-width - $min-width);
$b: ($start-unit * $max-width - $end-unit * $min-width) / ($max-width - $min-width);
$function: calc(#{$m} * 1vw + #{$b});

.box1 {
  background: green;
  left: $start-unit;
  @media (max-width: $max-width) and (min-width: $min-width) {
    left: $function;
  }
  @media (min-width: $max-width) {
    left: $end-unit;
  }
}
.box6 {
  background: green;
  width: $start-unit;
  @media (max-width: $max-width) and (min-width: $min-width) {
    width: $function;
  }
  @media (min-width: $max-width) {
    width: $end-unit;
  }
}
//Unrelated to demo styles
.box-position {
  position: relative;
  margin-bottom: 1rem;
  height: 80px;
  width: 80px;  
}
.box2, .box3 {
  background: red;
  display: inline-block;
}
.box2 {
  left: $start-unit;
}
.box3 {
  //Factor in the width of the box before and body margin
  left: $end-unit - 85;
}
.box-width {
  margin-bottom: 1rem;
  height: 80px;
}
.box4, .box5 {
  background: purple;
}
.box4 {
  width: $start-unit;
}
.box5 {
  width: $end-unit;
}
              
            
!

JS

              
                
              
            
!
999px

Console