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

              
                h1.intro hexagon
  small hexagon transformer

.box
  .hexagon

///////

form.ctrl
  .table
    .td
      h4 border radius

      label
        input(type="checkbox", checked, data-str="radius.linked")
        | linked?
      label horizontal radius:
        input.block#radius-h(type="range", min="0", max="100", data-str="radius.h", value="50")
      label vertical radius:
        input.block#radius-v(type="range", min="0", max="100", data-str="radius.v", value="50")

      | unit: 
      br

      label.ib
        input.radius-unit(type="radio", name="radius-unit", value="%", checked, data-str="radius.unit")
        | %
      label.ib
        input.radius-unit(type="radio", name="radius-unit", value="px", data-str="radius.unit")
        | px

    .td
      h4 color

      label color(#rgb):
        input.block#color-hex(type="color" value="#ff0000", data-str="color.hex")
      label alpha:
        input.block#color-alpha(type="range", min="0", max="1", step="0.01", value=".5", data-str="color.alpha")

      input.block#reset(type="reset")

      p
        a#permalink(href="###") permalink

  h4 style preview
  pre <style id="inline" contenteditable=""></style>
              
            
!

CSS

              
                $box-size = 25em;
$unit-size = 2em;

///
/// major style
///

.hexagon {
  position: relative;
  width: 2 * $unit-size * tan(60deg);
  height: 2 * $unit-size;
  margin: $unit-size auto;
  color: rgba(#f00, .5);
  font-size: 16px;
  background-color: currentColor;

  &::before,
  &::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: inherit;
  }

  &::before { transform: rotate(60deg); }
  &::after { transform: rotate(-60deg); }

  &,
  &::before,
  &::after {
    border-radius: 50% / 50%;
  }
}




.box {
  position: relative;
  width: $unit-size * 8;
  // height: $unit-size * 8;
  margin: ($unit-size * 1) auto;
  overflow: hidden;

  &:hover  * {animation-play-state: paused; }
  &:active * {animation-play-state: running; }
}

.ctrl {
  max-width: 30rem;
  margin: auto;
  text-align: left;

  .table {
    width: 100%;
    table-layout: fixed;
    display: table;
  }

  .td {
    display: table-cell;
    vertical-align: top;
    margin: 2% 0%;
    background-color: rgba(#999, .1);
    padding: 1% 3%;
  }

  h4 {
    margin: 1em 0;
  }

  label {
    display: block;
    margin-bottom: 1em;
    cursor: pointer;
  }

  .ib {
    display: inline-block;
    width: 3em;
  }

  input.block {
    display: block;
    width: 80%;
    margin-left: 10%;
    margin-right: 10%;
  }

  input {
    cursor: pointer;
  }

  a {
    color: inherit;
  }

  style {
    display: block;
    padding: 1em;
    word-break: break-word;
    opacity: .5;

    &.update {
      animation: update 1s linear 1;
    }
  }
}


@keyframes update {
  0%   { background-color: rgba(#ff0,.7);}
  100% { background-color: rgba(#fff,0);}
}


///
/// reset style
///

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  padding-top: 1px;
  text-align: center;
  /* background-color: #2b2e2d; */
  /* color: #e4e3c8; */
}

.intro {
  width: 80%;
  max-width: 30rem;
  padding-bottom: 1rem;
  margin: .5em auto 1em;
  text-transform: capitalize;
  border-bottom: 1px dashed #999;

  small {
    display: block;
    opacity: .5;
    font-style: italic;
    text-transform: capitalize;
  }
}

              
            
!

JS

              
                /* global document, console, window */

(function () {
  'use strict';

  var inputs = document.getElementsByTagName('input');
  var varInput = document.querySelectorAll('[data-str]');
  var style = document.getElementById('inline');
  var permalink = document.getElementById('permalink');
  var data = {
    color: {
      hex: '#9900ff',
      alpha: 0.6
    },
    radius: {
      h: 0,
      v: 0,
      linked: true,
      unit: '%'
    }
  };

  var updateData = function(inputArray, _id) {
    inputArray = inputArray ? inputArray : varInput;

    [].forEach.call(inputArray, function(_input) {
      var _type = _input.type;

      if ('radio' === _type && !_input.checked) {return; }

      var pos = _input.getAttribute('data-str').split('.');
      var val = ('checkbox' === _type) ? _input.checked : _input.value;

      data[pos[0]][pos[1]] = val;
    });

    // if radius liined
    if (/radius/.test(_id) && data.radius.linked) {
      var linkedTargetId = ('radius-h' === _id) ? 'radius-v' : 'radius-h';
      var linkedTarget = document.getElementById(linkedTargetId);
      var changingItem = document.getElementById(_id);

      linkedTarget.value = changingItem.value;

      // update just another linked input value
      updateData([linkedTarget]);
    }

    updateState();
  };

  var updateState = function() {
    var dataExport = JSON.stringify(data);
    // history.pushState(null, null, location.href);
    // location.hash = 'go=' + dataExport;
    permalink.href = location.origin + location.pathname + '#go=' + dataExport;
  };

  var hex2Dec = function(hex) {
    return Number('0x' + hex.toString());
  };

  var rgba = function(hexColor, alpha) {
    hexColor = hexColor.trim().substr(1);
    alpha = (alpha !== undefined ? alpha : 1);

    var step = (hexColor.length / 3);
    var pattern = new RegExp('.{' + step + '}', 'g');
    var colorString = hexColor.match(pattern);
    var r, g, b;

    r = hex2Dec(colorString[0]);
    g = hex2Dec(colorString[1]);
    b = hex2Dec(colorString[2]);

    return 'rgba(' + [r,g,b,alpha].join(',') + ')';
  };

  var render = function() {
    style.textContent = '.hexagon, .hexagon::before, .hexagon::after {\n  color: ' + rgba(data.color.hex, data.color.alpha) + ';\n  border-radius: ' + [data.radius.h, data.radius.unit, ' / ', data.radius.v, data.radius.unit].join('') + ';\n}';

    style.className = '';

    setTimeout(function() {
      style.className = 'update';
    }, 30);
  };

  var bindChange = function() {
    [].forEach.call(varInput, function(_input) {
      _input.addEventListener('input', function() {
        renderWithUpdate(this.id);
      });
      _input.addEventListener('change', function() {
        renderWithUpdate(this.id);
      });
    });

    // bind reset
    document.getElementById('reset').addEventListener('click', function(e) {
      setTimeout(renderWithUpdate, 50);
    });
  };

  var renderWithUpdate = function(_id) {
    updateData(false, _id);
    render();
  };

  var init = (function() {
    var dataImport = location.hash.split('#go=');
    if (dataImport.length > 1) {
      data = JSON.parse(dataImport[1]);
    } else {
      updateData();
    }
    render();
    bindChange();
  })();

})();

              
            
!
999px

Console