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

              
                <main>
  <div class="wrapper">
    <article class="flow">
      <h1>Next sibling selector - out of control margin</h1>
      <figure class="callout">
        <p>
          Because the CSS applied with the <code>* + *</code> selector is recursive,
          we can get unwanted behaviour like unpredictable space.
        </p>
        <p>
          The semi-transparent red boxes show the margin being applied both where you might expect it to be and where you probably don’t want it to be.</p>
      </figure>
      <div class="top box">
        <p>I have no margin because I am the first child.</p>
        <p>
          I have <code>margin-top</code> because I am a <strong>next sibling</strong>.
        </p>
        <p>
          I have a <strong>bold</strong> <em>then an emphasised bit of text</em>,
          which because I put <code>inline-block</code> on my emphasised text, gives
          us unwanted spacing.
        </p>
      </div>
    </article>
  </div>
</main>
              
            
!

CSS

              
                .top * + * {
  margin-top: 1.5em;
}

em {
  display: inline-block;
}

/* Presentation styles */
.top p {
  border: 1px solid var(--color-primary);
  background: var(--color-light);
  padding: 1em;
}

/* Presentational styles */
.top * + * {
  position: relative;
}

.top * + *::before {
  content: "";
  width: 100%;
  height: 1.5em;
  background: #ff807b;
  position: absolute;
  bottom: 100%;
  left: 0;
  outline: 1px solid #9d0600;
  opacity: 0.5;
}
              
            
!

JS

              
                
              
            
!
999px

Console