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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <h1>Dirty &rsquo;orrible &rsquo;acky Safari resize fix</h1>
<p>Safari only: Fix for onresize inside an iframe (vw &amp; vh too).<br>For example: In a Codepen iframe.</p>

<figure>
  <figcaption>Is JavaScript no?</figcaption>
  <pre><code spellcheck=false contenteditable>// Safari only - Fix for onresize inside a Codepen iframe
(function () {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf('safari') != -1) {
    if (!(ua.indexOf('chrome') > -1)) {

      // Safari only
      console.log("99 problems and Safari's just one.");
      window.addEventListener("resize", function() {
        window.location.reload(false);
      }, false);
    }
  }
}());</code></pre>
</figure>

<p>Couldn&rsquo;t find a repair for Safari failing to recalculate iframe and vw / vh sizes when the browser is resized, so wrote this.</p>
<p>It&rsquo;s certainly a dirty &rsquo;orrible &rsquo;acky fix, not recommended for production, but make&rsquo;s a good starter for ten.</p>

<p>Uses <a target=_blank title="[new window]" href="https://websemantics.uk/tools/responsive-font-calculator/">Fluid-responsive font-sizes</a> for testing purposes.</p>


    <p><a target=_blank title="[new window]" href="https://codepen.io/2kool2/pens/popular/?grid_type=list#">Pens by Mike Foskett</a> &mdash; <a target=_blank title="[new window]" href="https://websemantics.uk/">webSemantics</a></p>
            
          
!
            
              :root {
  font-size: 1rem;
  font-family: sans-serif;
  line-height: 1.5;
}
/* 1em(16px) @ 20em(320px) increasing to 2em(32px) @ 40em(640px) */
@media (min-width: 20em) {
  :root {
    font-size: calc(1rem + ((1vw - 0.2em) * 5));
    font-weight: 100;
  }
}

body {
  margin: 1rem;
  background-color: #1a1a1a;
  color: #fff;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-shadow: 1px 1px #000;
}
h1 {
  font-size: 1.5rem;
  line-height: 1.2;
  font-weight: 100;
}
a {
  color: #fff !important;
  text-decoration: none;
  border-bottom: 1px solid #fff;
  transition: all .3s ease-out;
  outline: 0 solid #000;
}
a:hover,
a:focus {
  background-color: #000;
  outline: .25em solid #000;
}


figure {
  margin: 0;
  overflow: scroll;
  background-color: #3a3a3a;
  box-shadow: 0 0.25rem .5rem #000;
}
figcaption {
  padding: 0.5rem 1rem 0;
}
pre > code {
  display: block;
  padding: 0 1rem;
  outline: 0 solid;
  text-shadow: 1px 1px #000;
}
::-moz-selection {
  color: #fff;
  background-color: #000;
}
::selection {
  color: #fff;
  background-color: #000;
}
            
          
!
            
              
// Safari only - Fix for onresize inside a Codepen iframe
(function () {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.indexOf('safari') != -1) {
    if (!(ua.indexOf('chrome') > -1)) {

      // Safari only
      console.log("99 problems and Safari's just one.");
      window.addEventListener("resize", function() {
        window.location.reload(false);
      }, false);
    }
  }
}());
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console