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

              
                h1 z<sup>2</sup> + C iterations with fractions, in CSS!
p Open the Pen in its own window, then view the console to see precise values for each iteration. 
p Learn more about this phenomenon from Dr. Holly Kreiger <a href="https://www.numberphile.com/videos/fascinating-thing-about-fractions" target="blank">in this Numberphile video</a>.

div(class='wrap')
	div(class='outer',style='--z: 0; --C: 0;')
		- for (var i = 1; i <= 5; ++i) {
			div(class='render z'+ i)
		- }
	div(class='outer',style='--z: -7/4; --C: -29/16;')
		- for (var i = 1; i <= 5; ++i) {
			div(class='render z'+ i)
		- }

	div(class='outer',style='--z: 1; --C: -7/4;')
		- for (var i = 1; i <= 5; ++i) {
			div(class='render z'+ i)
		- }

	div(class='outer',style='--z: 1/2; --C: 1/4;')
		- for (var i = 1; i <= 5; ++i) {
			div(class='render z'+ i)
		- }

	div(class='outer',style='--z: 0; --C: -1;')
		- for (var i = 1; i <= 5; ++i) {
			div(class='render z'+ i)
		- }

              
            
!

CSS

              
                // As far as I know, we cannot iteratively 
// reassign the value of z in CSS; each iteration 
// here is calculated in a single expression that
// includes the previous expression. 
// In order to make this manageable, I used Sass 
// to DRY out these calculations.
$z1: calc(
			( var(--z) * var(--z) ) 
			+ var( --C ) 
		);

$z2: calc(
			( #{$z1} * #{$z1} ) 
			+ var( --C ) 
		);

$z3: calc(
			( #{$z2} * #{$z2} ) 
			+ var( --C ) 
		);

$z4: calc(
			( #{$z3} * #{$z3} ) 
			+ var( --C ) 
		);

$z5: calc(
			( #{$z4} * #{$z4} ) 
			+ var( --C ) 
		);

:root {
	--z: calc( 0 );
	--C: calc( 0 );
	--ui-adjustment: 100px;
}

// Assign the (massive) full expressions to 
// custom properties.
.outer {
	--z1: #{$z1};
	--z2: #{$z2};
	--z3: #{$z3};
	--z4: #{$z4};
	--z5: #{$z5};
}


// Why does translate not work here?
.z1 {
	margin-top: calc( var( --z1 ) * var( --ui-adjustment ) );
}	

.z2 {
	margin-top: calc( var( --z2 ) * var( --ui-adjustment ) );
}

.z3 {
	margin-top: calc( var( --z3 ) * var( --ui-adjustment ) );
}

.z4 {
	margin-top: calc( var( --z4 ) * var( --ui-adjustment ) );
}

.z5 {
	margin-top: calc( var( --z5 ) * var( --ui-adjustment ) );
}

// The math is over now. This code is only setting 
// up the interface.

* {
	box-sizing: border-box;
}

body {
	margin: 20px;
}

.outer:nth-child(2n) {
	--color: red;
}

.outer:nth-child(2n + 1) {
	--color: blue;
}

.outer:nth-child(3n) {
	--color: orange;
}

.outer:nth-child(3n + 1) {
	--color: green;
}

.wrap {
	display: grid;
	grid-template-columns: repeat(auto-fill, 200px);
	gap: 10px;
	margin-top: 30px;
}

.render {
	border: 2px solid var(--color);
	background-color: black;
	width: 10px;
	height: 10px;
}

.outer {
	position: relative;
	height: var( --ui-adjustment );
	margin-top: 30px;
	display: flex;
	gap: 20px;
	flex-wrap: wrap;
	align-items: center;
	border: 3px solid var(--color);
}

.outer::before {
	content: '';
	border: 1px solid black;
	position: absolute;
	translate: translateY(50%);
	width: 100%;
}

.outer::after {
	content: attr(style);
	position: absolute;
	top: -20px;
	white-space: nowrap;
}
              
            
!

JS

              
                // This JavaScript is for formatting and logging values 
// to the console. The math happens in CSS.

const sets = [ ... document.querySelectorAll( '.outer' ) ];

sets.forEach( ( set ) => {
	const title = set.className.split( ' ' )[1];
	const points = [ ... set.querySelectorAll( '.render' ) ];
	
	const data = points.reduce( ( allEls, el ) => {
		
		const style = window.getComputedStyle(el);

		const z = style.getPropertyValue('--z');
		const C = style.getPropertyValue('--C');

		const className = el.className.split(' ').filter( c => c[0] === 'z' )[0];

		const iteration = className[1];
		const expression = style.getPropertyValue( `--${className}`);

		const calc = ( e ) => eval( e );

		allEls[iteration] = {
			'value': calc( expression ),
		};

		return allEls;
	}, {});

	console.log( '\n\n\nStarting values:\n', set.style.cssText );
	console.table( data );
	
});





              
            
!
999px

Console