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.

            
              <div class="wrap">
  <p>Below you can interact with 3 <code>span</code> elements. Each button toggles styles on every span.</p>

  <p>Each span has a 30% width applied. The first group have varying line-heights, while the second have varying vertical paddings.</p>

  <p>Toggle the display and alignment buttons to see how the different properties interact.</p>
  <br />

  <div class="row">
    <div class="column small-6 medium-4">
      <button class="button expanded secondary js-toggle-prop" data-prop="display" data-value="inline">display: inline;</button>

      <button class="button expanded secondary js-toggle-prop" data-prop="display" data-value="block">display: block;</button>

      <button class="button expanded secondary js-toggle-prop" data-prop="display" data-value="inline-block">display: inline-block;</button>

      <hr />

      <button class="button expanded secondary js-toggle-prop" data-prop="vertical-align" data-value="top">toggle align top</button>

      <button class="button expanded secondary js-toggle-prop" data-prop="vertical-align" data-value="middle">toggle align middle</button>

      <button class="button expanded secondary js-toggle-prop" data-prop="vertical-align" data-value="bottom">toggle align bottom</button>
    </div>

    <div class="column small-6 medium-8">
      <p>
        <span class="target--line-heighted js-target">line-height span.</span>
        <span class="target--line-heighted js-target">line-height span.</span>
        <span class="target--line-heighted js-target">line-height span.</span>
      </p>
    </div>

    <div class="column small-6 medium-8">
      <p>
        <span class="target--padded js-target">padded span.</span>
        <span class="target--padded js-target">padded span.</span>
        <span class="target--padded js-target">padded span.</span>
      </p>
    </div>
  </div>
</div>
            
          
!
            
              .wrap {
  margin-left: auto;
  margin-right: auto;
  max-width: 780px;
}

.button.secondary {
  &.is-active { background-color: skyblue;}
}

%target {
  width: 30%;
  
  &:nth-child(odd) { 
    background-color: transparentize(skyblue, .8);
    outline: 1px solid transparentize(skyblue, .5);
  }
  
  &:nth-child(even) { 
    background-color: transparentize(hotpink, .8);
        outline: 1px solid transparentize(hotpink, .5);
  }
}
.target { @extend %target;}

.target--line-heighted {
  @extend %target;
  
  &:nth-child(2) { line-height: 4;}
  
  &:nth-child(3) { line-height: 6;}
}

.target--padded {
  @extend %target;
  
  &:nth-child(2) { padding: 1rem 0;}
  
  &:nth-child(3) { padding: 2rem 0;}
}
            
          
!
            
              const toggleTargets = document.querySelectorAll('.js-target');
const propTogglers = document.querySelectorAll('.js-toggle-prop');

function propToggler({ toggleElems, targetElems }) {
  const targets = [].slice.call(targetElems);
  const togglers = [].slice.call(toggleElems);
  const activeClassName = 'is-active';

  function init() {
    togglers.map(toggle => {
      toggle.prop = toggle.getAttribute('data-prop');
      toggle.value = toggle.getAttribute('data-value');
      toggle.isActive = false;
    });
    
    document.body.addEventListener('mouseup', handleClick);
  }
  
  function handleClick(e) {
    const target = e.target;
    
    togglers.map(toggle => {
      if (target === toggle) handleToggleClick(toggle);
    });
  }
  
  function handleToggleClick(toggle) {
    const isActive = toggle.isActive;
    const prop = toggle.prop;
    const value = !toggle.isActive ? toggle.value : '';
    
    targets.map((el) => el.style[prop] = value );
    
    deactivateAllByProp(prop);
    toggle.isActive = !isActive;
    
    if (toggle.isActive) addActiveClass(toggle);
  }
  
  function deactivateAllByProp(prop) {
    togglers.map(toggle => {
      if (toggle.prop === prop) {
        toggle.isActive = false;
        removeActiveClass(toggle);
      }
    });
  }
  
  function addActiveClass(toggle) {
    toggle.classList.add(activeClassName);
  }
  
  function removeActiveClass(toggle) {
    toggle.classList.remove(activeClassName);
  }
  
  init();
}

propToggler({
  toggleElems: propTogglers,
  targetElems: toggleTargets,
});
            
          
!
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