Pen Settings

HTML

CSS

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.

+ 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

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.

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>
	<h1>Remove Child Margin</h1>
	<p>Here’s a utility class I’ve started using a lot:</p>
<code><pre>.u-remove-child-margin {
  > :first-of-type {
    margin-top: 0;
  }

  > :last-of-type {
    margin-bottom: 0;
  }
}</pre></code>
	<p>It removes <code>margin-top</code> from the first child and <code>margin-bottom</code> from the last child.</p>
	
	<h2>Example</h2>
	<p><button id="toggle">Toggle utility class</button></p>
	<div id="example" class="box u-remove-child-margin">
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor sodales enim ac ultrices. In hac habitasse platea dictumst. Etiam orci mauris, placerat mollis nibh ut.</p>
		<p>Donec facilisis mi vitae diam imperdiet mattis. Proin at dui eget purus rhoncus dignissim id id ex. Aliquam dolor nibh, lacinia nec aliquam vel, auctor quis purus.</p>
		<p>Nunc vitae est ut erat porta rhoncus. Phasellus pulvinar libero nec auctor tempus. Donec mauris leo, tristique non imperdiet quis, ultricies id felis.</p>
	</div>
</main>

              
            
!

CSS

              
                /*
---
name: Remove Child Margin
category: Utilities
---
This utility removes the outer margin from an element's immediate children.

For example, if you have a `<div>` with two child `<p>` elements, this class removes `margin-top` from the
first `<p>` and removes `margin-bottom` from the last one.

To allow more flexibility with custom markup, we use `:first-of-type` and `:last-of-type` instead of
`:first-child` and `:last-child`. That way we can use the same class on components like tooltips
that require an extra `div` which would otherwise require additional CSS.

```remove-child-margin.html
<div class="u-remove-child-margin">
  <p>This child's margin-top is removed.</p>
  <p>This child stays the same.</p>
  <p>This child's margin-bottom is removed.</p>
  <div>This child's margin-top and margin-bottom are removed.</div>
</div>
```
*/
.u-remove-child-margin {
  > :first-of-type {
    margin-top: 0;
  }

  > :last-of-type {
    margin-bottom: 0;
  }
}



/* ------------------------------ */
/* Demo                           */
/* ------------------------------ */

html {
	box-sizing: border-box;
}

*,
::after,
::before {
	box-sizing: inherit;
}

body {
	margin: 1rem auto 3rem;
	line-height: 1.4;
	tab-size: 4;
}

main {
	display: block; /* Fix IE rendering main as inline */
	margin: 0 auto;
	max-width: 42rem;
	padding-left: 1rem;
	padding-right: 1rem;
}

pre {
	border: 1px solid #ccc;
	padding: 1rem;
	overflow: auto;
	-webkit-overflow-scroll: touch;
}

.box {
	max-width: fit-content;
  border: 1px solid #ccc;
	padding: 1rem;
}
              
            
!

JS

              
                toggle.addEventListener('click', function (event) {
	example.classList.toggle('u-remove-child-margin');
});

              
            
!
999px

Console