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="container">
  <div class="top">
    <h3>Colors</h3>
    <label>
      BG 1:
      <input type="color" id="bg1" value="#ffdd55" />
    </label>
    <label>
      Text 1:
      <input type="color" id="fg1" value="#000000" />
    </label>
    <label>
      BG 2:
      <input type="color" id="bg2" value="#ffdd55" />
    </label>
    <label>
      Text 2:
      <input type="color" id="fg2" value="#ffffff" />
    </label>
  </div>

  <div class="bottom">
    <div class="left">
      <div class="content">
        <h1>My Huge Page Title</h1>
        <p>Sed dapibus neque placerat nisi posuere, et porta nunc aliquam. Quisque at nisi quis mauris condimentum hendrerit a at libero. Nunc vestibulum tellus ut lacus fringilla, eget consectetur justo rhoncus.</p>
        <p class="small">Aenean consectetur sapien eu congue lobortis. Integer vitae cursus sapien, sed blandit felis.</p>
      </div>
    </div>

    <div class="right">
      <div class="content">
        <h1>My Huge Page Title</h1>
        <p>Sed dapibus neque placerat nisi posuere, et porta nunc aliquam. Quisque at nisi quis mauris condimentum hendrerit a at libero. Nunc vestibulum tellus ut lacus fringilla, eget consectetur justo rhoncus.</p>
        <p class="small">Aenean consectetur sapien eu congue lobortis. Integer vitae cursus sapien, sed blandit felis.</p>
      </div>
    </div>
  </div>
</div>
            
          
!
            
              :root {
  --bg1: #fd5;
  --bg2: #fd5;
  --fg1: #000;
  --fg2: #fff;
}

* {
  box-sizing: border-box;
}

body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  font: normal 19px/1.5 helvetica, sans-serif;
}

$width: 500px;
$height: 400px;
$padding: 3em;

.container {
  width: $width;
  height: $height;
  position: relative;
}

.top {
  position: absolute;
  top: -48px;
  font-size: .7em;

  h3 {
    margin: 0;
    padding: 0;
    margin-bottom: .5em;
    color: #333;
    display: inline-block;
  }

  label {
    margin-left: 1.75em;
  }

  input {
    margin-left: .1em;
  }
}

.bottom {
  position: relative;
  width: $width;
  height: $height;
  user-select: none;

  .left, .right {
    position: absolute;
    top: 0;
    left: 0;
    height: $height;
    overflow: hidden;

    .content {
      width: $width;
      padding: $padding;
    }
  }

  .left {
    width: 50%;
    max-width: 100%;
    min-width: 10px;
    resize: horizontal;
    z-index: 1;
    animation: demo 4.5s 1;

    .resizable-handle {
      width: 8px;
      height: 100%;
      background: rgba(#fec, .5);
      border-left: 1px solid rgba(#fff, .75);
      border-right: 1px solid rgba(#000, .06125);
      border-radius: 5px;
      box-shadow: 0 0 5px rgba(#000, .06125);
      transition: all .2s;
      
      &:hover {
        width: 10px;
        box-shadow: 0 0 10px rgba(#000, .125);
      }

      &-active {
        width: 13px !important;
        background: rgba(#fec, .65);
      }
    }
  }

  .left {
    background: var(--bg1);
    color: var(--fg1);
  }

  .right {
    background: var(--bg2);
    color: var(--fg2);
  }

  h1 {
    margin-top: 0;
  }

  .small {
    font-size: .75em;
  }
}

@keyframes demo {
  12.5% { width: 80%; }
  50% { width: 25%; }
  80% { width: 50% }
}
            
          
!
            
              function resizable(el) {
  const getX = e => e.clientX || e.touches[0].clientX

  const togglePressed = isActive => event => {
    if (state.pressed !== isActive) {
      state.pressed = isActive
      handle.classList.toggle('resizable-handle-active')
      state.x = isActive ? getX(event) : -1
    }
  }

  const move = event => {
    if (state.pressed) {
      const width = el.getBoundingClientRect().width
      const clientX = getX(event)
      const direction = state.x < clientX ? 1 : -1
      const diff = Math.abs(state.x - clientX) * direction
      el.style.cssText += `width: ${width + diff}px;`
      state.x = clientX
    }
  }

  const state = {
    pressed: false,
    x: -1
  }

  const handle = document.createElement('div')
  handle.classList.add('resizable-handle')
  handle.style.cssText += `
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    cursor: col-resize;
  `

  handle.addEventListener('mousedown', togglePressed(true))
  window.addEventListener('mouseup', togglePressed(false))
  window.addEventListener('mousemove', move)

  handle.addEventListener('touchstart', togglePressed(true))
  handle.addEventListener('touchend', togglePressed(false))
  handle.addEventListener('touchcancel', togglePressed(false))
  handle.addEventListener('touchmove', move)

  el.appendChild(handle)
}

const leftPanel = document.querySelector('.left')
resizable(leftPanel)

const reactiveCSSProps = createReactiveCSSProps({
  '--bg1': {
    reducer({ type, data }) {
      switch (type) {
        case 'bg1': return data.target.value
      }
    }
  },
  '--bg2': {
    reducer({ type, data }) {
      switch (type) {
        case 'bg2': return data.target.value
      }
    }
  },
  '--fg1': {
    reducer({ type, data }) {
      switch (type) {
        case 'fg1': return data.target.value
      }
    }
  },
  '--fg2': {
    reducer({ type, data }) {
      switch (type) {
        case 'fg2': return data.target.value
      }
    }
  }
})

;[ bg1, bg2, fg1, fg2 ].forEach(input => {
  input.addEventListener('change', event => {
    reactiveCSSProps.dispatch({ type: input.id, data: event })
  }) 
})
            
          
!
999px
Loading ..................

Console