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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <p>The test results are be viewed in the browser console, not the CodePen console. To see a failing version of the test, open this in a non-Firefox browser. This blog post has an explanation of why it is failing.</p>
<div class="a-space-children a-space-children-horizontal a-space-children--2">
		<div>Child</div>
		<div>Child</div>
		<div>Child</div>
		<div>Child</div>
</div>
<hr>
<div class="a-space-children a-space-children-vertical a-space-children--1">
		<div>Child</div>
		<div>Child</div>
		<div>Child</div>
		<div>Child</div>
</div>
              
            
!

CSS

              
                // Tokens Stub
$spacer-050: 0.5;
$spacer-1:   1;
$spacer-2:   2;

:root {
	--a-space-children-spacer: initial;
}

// This is the basic version with margins
.a-space-children-horizontal {
	display: flex;
	flex-wrap: wrap;
}

.a-space-children-horizontal > * + * {
	margin-left: $spacer-050 + rem;
	margin-left: calc( var( --a-space-children-spacer ) * 1rem );
}

.a-space-children-vertical > * + * { 
	margin-top: $spacer-050 + rem;
	margin-top: calc( var( --a-space-children-spacer, initial ) * 1rem );
}

// This is the enhanced version
// Blink browsers (tested Chrome 75.0.3770.100 and Safari 12.1) render this version as if they support gap, but the gap does not apply.
@supports ( gap: 1rem ) {

	.a-space-children-vertical,
	.a-space-children-horizontal {
		// Redundant declarations here so that the enhanced verison is not dependent on the basic version above
		display: flex;
		flex-wrap: wrap;
		gap: calc( var( --a-space-children-spacer, initial ) * 1rem );
	}
	
	.a-space-children-vertical {
		flex-direction: column;
	}
	
	.a-space-children-vertical > * + * {
		margin-top: unset;
	}

	.a-space-children-horizontal > * + * {
		margin-left: unset;
	}

}

.a-space-children--050 {
	--a-space-children-spacer: #{$spacer-050};
}

.a-space-children--1 {
	--a-space-children-spacer: #{$spacer-1};
}

.a-space-children--2 {
	--a-space-children-spacer: #{$spacer-2};
}

              
            
!

JS

              
                function describe( testString, tests ) {
	console.group( testString );
	tests();
	console.groupEnd();
}

function it( testString, test ) {
	let testResult = test();
	let color = false === testResult.result ? 'red' : 'green';

	console.log( `%c ${testString} ${testResult.message}`, `color:${color}` );
}

function assert( expression, log ) {
	let message = '';

	if ( false == expression ) {
		message = '\n \t Fail: ' + log;
	}

	return {
		result: expression,
		message: message
	};
}

function tests() {

	describe( 'a-space-children-vertical', () => {

		const parents = document.querySelectorAll( '.a-space-children-vertical' );

		if ( parents.length > 0 ) {

			parents.forEach( parent => {
				const children = parent.querySelectorAll( ':scope > * ');
				const parentBox = parent.getBoundingClientRect();

				it( 'does not apply a space above the first item', () => {
					let kid = children[0];

					return assert( 
						parentBox.top === kid.getBoundingClientRect().top, 
						`${parentBox.top}, ${kid.getBoundingClientRect().top}`
					);
				});

				it( 'spaces children', () => {
					let kid1 = children[1].getBoundingClientRect();
					let kid2 = children[2].getBoundingClientRect();
					
					const spaceInPixels =  parseInt( window.getComputedStyle( parent ).getPropertyValue( '--a-space-children-spacer' ) ) * 16; 
					
					return assert( 
						kid1.bottom % ( parseInt(kid2.top) - spaceInPixels ) < 1, 
						`${kid1.bottom}, ${( parseInt(kid2.top) - spaceInPixels )}`
					);
				});
		
				it( 'does not apply a space below the last item', () => {
					let kid = children[ children.length - 1 ];

					return assert(
						parentBox.bottom === kid.getBoundingClientRect().bottom,
						`${parentBox.bottom}, ${kid.getBoundingClientRect().bottom}`
					);
				});
		
			});
		}

	});

	describe( 'a-space-children-horizontal', () => {

		const parents = document.querySelectorAll( '.a-space-children-horizontal' );
		
		if ( parents.length > 0 ) {
				
			parents.forEach( parent => {
				const children = parent.querySelectorAll( ':scope > * ');
				const parentBox = parent.getBoundingClientRect();

				it( 'does not apply a space left of the first item', () => {
					let kid = children[0];

					return assert(
						parentBox.left === kid.getBoundingClientRect().left,
						`${parentBox.left}, ${kid.getBoundingClientRect().left}`
					);
				});

				it( 'spaces children', () => {
					let kid1 = children[1].getBoundingClientRect();
					let kid2 = children[2].getBoundingClientRect();
					
					const spaceInPixels = parseInt( window.getComputedStyle( parent ).getPropertyValue( '--a-space-children-spacer' ) ) * 16; 

					 // Values are within 1px of each other.
					return assert( 
						kid1.right % ( parseInt(kid2.left) - spaceInPixels ) < 1,
						`${kid1.right}, ${kid2.left}`
					);
				});

			});

		}
	});
	
}

window.addEventListener( 'load', function() {
	tests();
});
              
            
!
999px

Console