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 4 <code>span</code> elements. Spans are by default inline-level elements.</p>
  
  <p> Each button toggles styles on every span.</p>

  <p>Toggle the buttons to see how the different display properties behave with other vertical and horizontal CSS properties.</p>
  <br />

  <div class="row">
    <div class="column small-6 medium-4">
      <button class="button expanded secondary js-toggle-prop" data-prop="outline" data-value="1px solid skyblue">toggle visible layout</button>
      
      <hr>
      
      <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="width" data-value="100%">toggle 100% width</button>

      <button class="button expanded secondary js-toggle-prop" data-prop="padding" data-value="10px 0">toggle vertical padding</button>

    </div>

    <div class="column small-6 medium-8">
      <span class="target js-target">Four.</span>
      <span class="target js-target">Adjacent.</span>
      <span class="target js-target">Spans.</span>
      <span class="target js-target">This span contains a far longer piece of text than the prevous three spans.</span>
    </div>
  </div>
</div>
            
          
!
            
              .wrap {
  margin-left: auto;
  margin-right: auto;
  max-width: 780px;
}

.button.secondary {
  &.is-active {
    background-color: skyblue;
  }
}
            
          
!
            
              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