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.

            
              <div class='example-box'>
  <div class='example static'>
    <h3>Static</h3>
    <div class='stats'>
    </div>
    <div class='body'></div>
  </div>
  <div class='example adaptive'>
    <h3>Adaptive</h3>
    <div class='stats'></div>
    <div class='body'></div>
  </div>
  <div class='example fluid'>
    <h3>Fluid</h3>
    <div class='stats'></div>
    <div class='body'></div>
  </div>
 </div>
            
          
!
            
              $serif: 'Crimson Text', serif;
$sans: 'Roboto', sans-serif;
$mono: 'Monaco', monospace;

$grey: #666;
$blue: #0655bd;
$red: #b14343;

$m-med: 800px;
$m-sml: 560px;
$m-mni: 375px;

@function st($n) { // strip units from a number
  @if type-of($n) == 'number' and not unitless($n) {
    @return $n / ($n * 0 + 1);
  }
  @else {
    @return $n;
  }
}

@function li($x0, $x1, $y0, $y1, $x) { // linear interpolation for fonts
  @return calc(0% + #{$y0} + (#{unquote($x)} - #{$x0}) * (#{st($y1 - $y0)} / #{st($x1 - $x0)}));
}

@function li2($x0, $x1, $y0, $y1, $x) { // linear interpolation for lengths
  @return calc(#{$y0} + (#{unquote($x)} - #{$x0}) * (#{st($y1 - $y0)} / #{st($x1 - $x0)}));
}

div.example-box {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
  width: calc(100vw - 40px);
  max-width: 1400px;
  margin: 0 auto;
  @media (max-width: $m-sml) {
    flex-direction: column;
  }
  div.example {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    flex-basis: 0;
    flex: 1;
    margin: 20px 20px 20px 0;
    @media (max-width: $m-sml) {
      margin: 0 10px 20px 10px;
    }
    &:last-child {
      margin: 20px 0;
      @media (max-width: $m-sml) {
        margin: 0 10px;
      }
    }
    h3 {
      font-family: $sans;
      font-size: 18px;
      margin: 0 0 10px 0;
    }
    div.body {
      width: 100%;
      padding: 30px;
      margin: 0 0 5px 0;
      background-color: #eee;
      border-radius: 4px;
      box-shadow: inset 0px 1px 3px 0px rgba(0,0,0,0.2);
      box-sizing: border-box;
      font-family: $serif;
      line-height: 125%;
    }
    div.stats {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: center;
      width: 100%;
      padding: 0 30px;
      margin: 0 0 10px 0;
      box-sizing: border-box;
      @media (max-width: $m-med) {
        padding: 0 10px;
      }
      p.stat-line {
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        width: 80%;
        min-width: 100px;
        margin: 0 0 0 0;
        font-family: $mono;
        font-size: 12px;
        white-space: nowrap;
        position: relative;
        span.stat-val {

        }
        span.stat-unit {
          color: $grey;
          position: absolute;
          right: -20px;
        }
      }
    }
  }
}

div.example-box {
  div.example {
    div.body {
      font-size: 16px;
    }
    &.static {

    }
    &.adaptive {
      div.body {
        @media (max-width: 1060px) {
          font-size: 13.01px;
        }
        @media (max-width: 820px) {
          font-size: 9.14px;
        }
        @media (max-width: $m-sml) {
          font-size: 16px;
        }
        @media (max-width: 460px) {
          font-size: 12.36px;
        }
        @media (max-width: 375px) {
          font-size: 9.27px;
        }
      }
    }
    &.fluid {
      div.body {
        @media (max-width: 1438px) {
          font-size: li(0px,393px,0px,16px,'(((100vw - 80px) / 3) - 60px)');
        }
        @media (max-width: $m-sml) {
          font-size: li(0px,440px,0px,16px,'(((100vw - 60px) / 1) - 60px)');
        }
      }
    }
  }
}
            
          
!
            
              document.addEventListener('DOMContentLoaded', () => {

  // constants
  const text = 'But they could not blame her, for through her eyes now shone the sun, and her veins were as fire. She lifted her gaze to the stars and the stars gazed back, their gentle shimmers whispering words that were not words, her instruments seeming to come alive with their voices of heat and light. Her ship&#146;s grievous damage was nothing; now, no one could stop them.';
  const stats = [{
    name: 'width',
    unit: 'px',
  },{
    name: 'font size',
    unit: 'px',
  },{
    name: 'cpl',
    unit: '',
  }];
  const is_safari = !!navigator.userAgent.match(/Version\/[\d\.]+.*Safari/);

  // elements
  var EXPL = $('div.example');

  // listeners
  window.addEventListener('resize', window_resize);

  // stack
  let stat_block = '';
  stats.forEach((c) => {
    stat_block += cr('p', {
      class: 'stat-line',
      children: [
        c.name + ': ',
        cr('span', {
          class: 'stat-val',
        }),
        cr('span', {
          class: 'stat-unit',
          children: [
            c.unit,
          ],
        }),
      ],
    });
  })
  EXPL.forEach((c) => {
    $('div.body',c).innerHTML = text;
    $('div.stats',c).innerHTML = stat_block;
  });
  setTimeout(() => {
    window_resize();
  },100);

  // functions

  function $(t,s) {
    if (s === undefined) {
      s = document;
    }
    let y = Array.prototype.slice.call(s.querySelectorAll(t));
    if (y.length > 1) {
      return y;
    }
    else {
      return y[0];
    }
  }

  function css(x) {
    return window.getComputedStyle(x);
  }

  function cr(x,o) {
    let html = '';
    html += '<' + x;
    let k = [];
    Object.keys(o).forEach((c) => {
      if (c !== 'children') {
        html += ' ' + c + '="' + o[c] + '"';
      }
      else {
        k = o[c];
      }
    });
    html += '>';
    if (k.length > 0) {
      k.forEach((c) => {
        html += c;
      });
    }
    html += '</' + x + '>';
    return html;
  }

  function window_resize() {
    EXPL.forEach((c) => {
      const wdh = c.offsetWidth - 60;
      const fsz = parseFloat(css($('div.body',c))['font-size']);
      const cpl = wdh / fsz * 2.1;
      let P = $('div.stats p span.stat-val',c);
      P[0].innerHTML = wdh;
      P[1].innerHTML = fsz.toFixed(2);
      P[2].innerHTML = cpl.toFixed(2);
    });
    document.querySelector('div.example.fluid div.body').style.zIndex = 1;
    if (is_safari) {

    }
  }

});
            
          
!
999px
Loading ..................

Console