Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <div id="tree" class="tree">
  <!--
    Put markup here.
    Even go arbitrary XML, if you like.
    e.g:
    <LivingThings>
      <Bacteria>
        <Some></Some>
        <Utter>
          <Shit></Shit>
        </Utter>
      </Bacteria>
      <Humans>
        <Me>
          <M></M>
          <E></E>
        </Me>
        <You></You>
      </Humans>
    </LivingThings>
  -->
  <div>
    <header>
      <h1>Title</h1>
      <nav>
        <a href="#">A link</a>
        <a href="#">Another link</a>
      </nav>
    </header>
    <main>
      <img src="http://enes.in/f.png" />
      <p>Ea commodo consequat duis autem vel eum iriure dolor in hendrerit.</p>
      <p>Decima eodem modo typi qui nunc nobis videntur.</p>
      <p>Tincidunt ut laoreet dolore magna, aliquam erat volutpat ut wisi enim ad minim.</p>
      <p>Id quod mazim, placerat facer possim assum typi non!</p>
      <p>Legere me lius quod ii, <a href="#">legunt saepius</a> claritas.</p>
      <p>Gothica quam nunc putamus parum claram anteposuerit litterarum formas humanitatis per seacula.</p>
    </main>
    <footer>
      <ul>
        <li><a href="#">Foo</a></li>
        <li><a href="#">Bar</a></li>
        <li><a href="#">Bam</a></li>
        <li><a href="#">Baz</a></li>
        <li><a href="#">Trek</a></li>
      </ul>
    </footer>
  </div>
</div>
              
            
!

CSS

              
                $height: 4.5vw;

html, body {
  width: 100%;
  height: 100%;
}

body {
  font: normal 100 100%/1.5 helvetica, arial, sans-serif;
  perspective: 500px;
}

.tree {
  position: relative;
  
  * {
    box-sizing: border-box;
    position: absolute;
    display: block;
    height: $height;
    bottom: $height * -2;
    transform: translateX(5%);
    font-size: .95em;
    text-align: center;
    line-height: $height;
    border: 1px solid transparent;
    border-radius: 3px;
    background: #999;
    color: #fff;
    transition: all .3s;
    
    &:hover {
      background: #27f;
      border-color: black;
      
      &::before {
        background: black;
      }
    }
    
    &::before {
      content: "";
      position: absolute;
      top: -$height;
      left: 50%;
      transform: translate(-5%);
      width: 2px;
      height: calc(#{$height} - 1px);
      background: inherit;
    }
  }
}

@media (max-width: 500px) {
  .tree {
    width: 175%;
    
    * {
      height: 30px;
      bottom: 30px * -2;
      line-height: 30px;

      &::before {
        top: -30px;
        height: 29px;
      }
    }
  }
}

@media (max-width: 300px) {
  .tree {
    width: 250%;
  }
}
              
            
!

JS

              
                var App = (function() {
  
  function getLevelNodes(node) {
    return Array.from(node.parentNode.children)
  }
  
  function getChildIndex(node) {
    return getLevelNodes(node).indexOf(node)
  }
  
  function tagNodeName(node) {
    node.innerHTML = node.nodeName + node.innerHTML
  }
  
  function clearInside(node) {
    Array.from(node.childNodes).forEach(child => {
      if (child.nodeName === '#text') {
        child.remove()
      }
    })
  }
  
  function handleImage(node) {
    if (node.nodeName === 'IMG') {
      node.src = ''
      node.alt = 'IMG'
    }
  }
  
  function walk(node, cb) {
    cb(node)
    if (node.children.length) {
      walk(node.children[0], cb)
    }
    if (node.nextElementSibling) {
      walk(node.nextElementSibling, cb)
    }
  }
  
  function init() {
    var $el = document.getElementById('tree')
    walk($el.children[0], node => {
      var levelNodes = getLevelNodes(node)
      var childIndex = getChildIndex(node)
      var width = 90 / levelNodes.length
      var leftSlice = 100 / levelNodes.length
      var left = leftSlice * childIndex
      clearInside(node)
      tagNodeName(node)
      handleImage(node)
      node.style.cssText += `;
        width: ${width}%;
        left: ${left}%;
      `
    })
  }
  
  return { init }
  
})()

document.addEventListener(
  'DOMContentLoaded',
  App.init.bind(App)
)
              
            
!
999px

Console