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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                - @units = [['em','font-relative','This unit represents the calculated font-size of the element. If used on the font-size property itself, it represents the inherited font-size of the element.'],['ex','font-relative',"This unit represents the x-height of the element's font. On fonts with the 'x' letter, this is generally the height of lowercase letters in the font; 1ex ≈ 0.5em in many fonts."],['ch','font-relative',"This unit represents the width, or more precisely the advance measure, of the glyph '0' (zero, the Unicode character U+0030) in the element's font."],['rem','font-relative',"This unit represents the font-size of the root element (e.g. the font-size of the <html> element). When used on the font-size on this root element, it represents its initial value."],['vh','viewport-percentage',"1/100th of the height of the viewport."],['vw','viewport-percentage',"1/100th of the width of the viewport."],['vmin','viewport-percentage',"1/100th of the minimum value between the height and the width of the viewport."],['vmax','viewport-percentage',"1/100th of the maximum value between the height and the width of the viewport."],['px','absolute',"Relative to the viewing device."],['mm','absolute',"One millimeter."],['cm','absolute',"One centimeter (10 millimeters)."],['in','absolute',"One inch (2.54 centimeters)."],['pt','absolute',"One point (which is 1/72 of an inch)."],['pc','absolute',"One pica (which is 12 points)."],['mozmm','absolute',"An experimental unit which attempts to render at exactly one millimeter regardless of the size or resolution of the display. This is rarely actually what you want, but may be useful in particular for mobile devices."]]

%html{"ng-app"=>"cssUnits",:style=>"font-size: {{ htmlSize }}px;","ng-controller"=>"controls"}
  %body{:style=>"font-size: {{ bodySize }}px;"}
    %section.sidebar
      %h1 CSS Units
      .key
        %p There are 3 types of CSS units:
        %label.label-font-relative
          %input{:type=>"checkbox", "ng-model"=>"fontrelative"}
          %strong font relative
          &mdash; changes on font-size and unit size.
        %label.label-viewport-percentage
          %input{:type=>"checkbox", "ng-model"=>"viewportpercentage"}
          %strong viewport percentage
          &mdash; changes on viewport size and unit size.
        %label.label-absolute
          %input{:type=>"checkbox", "ng-model"=>"absolute"}
          %strong absolute
          &mdash; changes only on unit size.
      %form
        %p Change these values or resize the browser to see how the units change.
        .form-control
          %label{:for=>"units"}
          %input#units{"ng-model"=>"unit",:type=>"number",:min=>"1"}
          units
        .form-control
          %label{:for=>"bodySize"} body { font-size:
          %input#bodySize{"ng-model"=>"bodySize",:type=>"number",:min=>"0"}
          px; }
        .form-control
          %label{:for=>"htmlSize"} html { font-size:
          %input#htmlSize{"ng-model"=>"htmlSize",:type=>"number",:min=>"0"}
          px; }
      %p 
        Content from
        %a{:href=>"https://developer.mozilla.org/en-US/docs/Web/CSS/length"} MDN
    %section.examples
      .read-more {{more}}
      - @units.each do |u| 
        %input{:type=>"radio",:id=>"example-#{u[0]}",:name=>"unit", "ng-model"=>"more", :value=>"#{u[0]} - #{u[2]}"}
        %label{:for=>"example-#{u[0]}","ng-show"=>"#{u[1].gsub(/-/, "")}"}
          .example{:class=>"example-#{u[0]} type-#{u[1]}",:href=>"#example-#{u[0]}",:style=>"width: {{ unit }}#{u[0]}; height: {{ unit }}#{u[0]}",:title=>"{{unit}}#{u[0]}"}
              
              
            
!

CSS

              
                $header-bg: #2c3e50;
$body-bg: #ecf0f1;
$font:  #16a085;
$viewport: #3498db;
$absolute:  #8e44ad;

$font-size: 14px;

$break: 650px;

* {
  box-sizing: border-box;
}
html,body {
  width: 100%;
  height: 100%;
}
body {
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  line-height: 1.45;
  color: #333;

  // background from http://lea.verou.me/css3patterns/#blueprint-grid
  background-color: $body-bg;
  background-image: linear-gradient(white 2px, transparent 2px),
    linear-gradient(90deg, white 2px, transparent 2px),
    linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);
  background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
  background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
  background-attachment: scroll;

}


h1 {
  font-size: 40px;
  margin-bottom: 20px;
}
p {
  margin-bottom: 1.3em;
}

strong, .unit {
  font-weight: 700;
}

.sidebar {
  background: $body-bg;
  padding: 10px;
  font-size: $font-size;
 
}
@media(min-width: $break) {
  .sidebar {
    max-width: 30vw;
    float: left;
    height: 100vh;
    margin-right: 10px;
    position: fixed;
    overflow:scroll;
  }
}


form {
  position: relative;
  border-bottom: 1px solid rgba(black,0.1);
  margin-bottom: 1.5em;
  padding-bottom: 1em;
  input {
    font-size: 1em;
    padding: 0.25em 0.5em;
    font-family: inherit;
    max-width: 3.5em;
    border: none;
    background: lighten($header-bg,5%);
    color: white;
    border-radius: 5px;
  }
}
.form-control { 
  margin-bottom: 10px;
}

.key {
  border-bottom: 1px solid rgba(black,0.1);
  margin-bottom: 1.5em;
  padding-bottom: 1em;
  label {
    display: block;
    clear: both;
  }
  input {
    position: relative;
    text-indent: -25px;
    float: left;
    display: inline-block;
    margin-bottom: 40px;
    margin-right: 10px;
  }
  .label-font-relative strong {
    background: $font;
  }
  .label-viewport-percentage strong {
    background: $viewport;
  }
  .label-absolute strong {
    background: $absolute;
  }
  strong {
    color: white;
    display: inline-block;
    padding: 0 0.25em; 
    border-radius: 0.2em;
  }

}


.examples {
  padding: 20px;
 
}

@media(min-width: $break) {
  .examples {
     margin-left: 30vw;
  }
}

.example {   
  display: inline-block;
  position: relative;
  margin-bottom: 70px;
  color: inherit;
  cursor: help;

  &:after {
    content: attr(title);
    position: absolute;
    font-size: 14px;
    transform: rotate(90deg) translate(50%, 50%);
    top: 100%;
    display: block;
    left: 50%;
  }
}


.type-font-relative, {
  background: $font;
  &:hover {
    background: darken($font, 10%);
  }
}
.type-viewport-percentage {
  background: $viewport;
  &:hover {
    background: darken($viewport, 10%);
  }
}

.type-absolute {
  background: $absolute;
  &:hover {
    background: darken($absolute, 10%);
  }
}


input[type="radio"] { display: none; }

.read-more {
  
  z-index: 10;
  font-size: $font-size;
  background: rgba(white,0.75);
  padding: 1em;
  margin-bottom: 1em;
  max-width: 30em;
  &:empty {
    background: none;
  }
}

@media(min-width: $break) {
  .read-more {
    position: absolute;
  bottom: 5px; right: 15px;
  }
}
              
            
!

JS

              
                angular.module('cssUnits', [])
.controller('controls', ['$scope', function($scope) {
  $scope.unit = 2;
  $scope.bodySize = 16;
  $scope.htmlSize = 16;
  $scope.fontrelative = true;
  $scope.viewportpercentage = true;
  $scope.absolute = true;
}]);

              
            
!
999px

Console