cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <h2>vw method</h2>
<div class="vw-method box">
  <p>If the width of the box is 100% of the viewport, you can use a height with a vw value. (1vw is 1/100th of the width of the viewport.)
  
  <p>Advantages:</p> 
    <ul>
      <li>No extra wrappers necessary. 
      <li>Less scss.
    </ul>

  <p>Disadvantages:</p>
  
  <ul>
    <li>less browser compatible (no IE8 and below)</li> 
    <li>(In Chrome at least) vw includes the scrollbar in the calculation, so the ratio is not perfect when scrollbars are present.</li>
  </ul>
</div>

<h2>padding/absolute method</h2>
<div class="padding-absolute-method box">
  <div class="content">
    <p>Using an extra wrapper, padding on a before pseudo class and absolutely positioning the inner div method.</p>
    
    <p>This works because a padding percentage (even for top or bottom padding) is calculated based on the WIDTH of the element.</p>

  <ul>
    <li>More compatible.
    <li>Not limited to full viewport width. (Can be used at any width.)
    <li>Extra inner wrapper required.
    <li> blah
      <li>blah
        <li>blah
    <li> blah
      <li>blah
        <li>blah
    </ul>
      </div>
</div>
            
          
!
            
              .vw-method {
  width: 100%;
  //Change the height to the desired aspect ratios width divided by height times 100vw
  height: 1/8 * 100vw; //8:1 ratio
  //height: 33.33vw; //3:1 ratio
  //height: 66.66vw; //3:2 ratio
  //height: 9/16 * 100vw; //16:9 ratio
  //height: 1/2 * 100vw; //2:1 ratio  
  
}

@mixin aspect-ratio($width, $height) {
  position: relative;
  &:before {
    display: block;
    content: "";
    width: 100%;
    padding-top: ($height / $width) * 100%;
  }
  > div {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}

.padding-absolute-method {
  // Change the parameters of this mixin to any desired aspect ratio.
  @include aspect-ratio(8,1);
}


.box {
  padding: 0px;
  background-color: #46433A;
  color: #dcd2b9;
  margin:0px 0px 50px 0px;
  overflow:hidden;
}

/* Irrelevant styling CSS */

@import url(https://fonts.googleapis.com/css?family=Merriweather:300,300italic|Lato:900,900italic);

body {
    font-family: Merriweather,Georgia,Times,"Times New Roman",serif;
    color: #46433A;
    font-size: 16px;
    font-size: 1rem;
    line-height: 1.5;
    // lighter background
    background-color: #E2D9C4;
    // slightly darker background
    background-color: rgb(219, 208, 182);
    margin: 0;
    font-weight: 300;
  }

h1, h2, h3, h4, h5, h6 {
    font-family: Lato,"Helvetica Neue","Segoe UI",Arial,sans-serif;
    text-rendering: optimizeLegibility;
    font-weight: 900;
    text-align: center;
}
            
          
!
999px
Loading ..................

Console