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.

            
              <h1>Equal Spacing without <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/margin_collapsing">margin-collapsing</a></h1>
<h2>First child display:none proof</h2>
<header class="Header">
  <div class="Header-item" style="display:none;">Item</div>
  <div class="Header-item">Item</div>
  <div class="Header-item">Item</div>
  <div class="Header-item">Item</div>
</header>

<h2>First child & (sibling * n) display:none proof</h2>
<header class="Header">
  <div class="Header-item" style="display:none;">Item</div>
  <div class="Header-item" style="display:none;">Item</div>
  <div class="Header-item">Item</div>
  <div class="Header-item">Item</div>
</header>
<h2>Last child display:none proof</h2>
<header class="Header">
  <div class="Header-item">Item</div>
  <div class="Header-item">Item</div>
  <div class="Header-item">Item</div>
  <div class="Header-item" style="display:none;">Item</div>
</header>

<a href="http://simurai.com/blog/2014/05/25/spacing-elements/">See simurai post for more context.</a>
            
          
!
            
              /* This method works because we use first child which allows us to go down the dom*/

.Header-item {
  margin-right: 2rem;
  
  &:first-child {
    margin-left: 2em;
    
    // find the next selector after the first child that isn't hidden and add margin-left on it.
    &[style*="display:none;"]
 ~ .Header-item:not([style*="display:none;"]) {
        margin-left:2em;
      
      // after we have found that selector reset it back
      & ~ .Header-item {
        margin-left: initial; //margin-left:0;
      }
    }
  }
}

.is-hidden {
  display:none;
}

/* ------------------------------------ */

.Header {
  display: flex;
  background: hsl(219, 79%, 88%);
}

.Header-item {
  flex: 1;
  text-align: center;
  line-height: 3;
  color: white;
  background: hsl(219, 79%, 66%);
}

body {
  font-size: 18px;
  font-family: Avenir, sans-serif;
  text-align:center;
}
            
          
!
            
              // In reply to this:
// http://simurai.com/blog/2014/05/25/spacing-elements/

            
          
!
999px
Loading ..................

Console