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

              
                <input id="hidefloats" type="checkbox">
<label for="hidefloats">
	Remove floats
</label>

<main>

	<section>
		<div>NO collapse v</div>
		<div class="col cfnc">
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div>3 collapsing</div>
			<div>4 collapsing</div>
		</div>
		<div>NO collapse ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>COLLAPSE v</div>
		<div class="col cf">
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div>3 collapsing</div>
			<div>4 collapsing</div>
		</div>
		<div>COLLAPSE ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>NO collapse v</div>
		<div class="col cfnc">
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div class="float">3A float</div>
			<div>3 collapsing</div>
			<div>4 collapsing</div>
		</div>
		<div>NO collapse ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>COLLAPSE v</div>
		<div class="col cf">
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div class="float">3A float</div>
			<div>3 collapsing</div>
			<div>4 collapsing</div>
		</div>
		<div>COLLAPSE ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>NO collapse v</div>
		<div class="col cfnc">
			<div class="float">1A float</div>
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div>3 collapsing</div>
			<div class="float">4A float</div>
			<div>4 collapsing</div>
		</div>
		<div>NO collapse ^</div>
		<div class="float">5 float</div>
	</section>

	<section>
		<div>COLLAPSE v</div>
		<div class="col cf">
			<div class="float">1A float</div>
			<div>1 collapsing</div>
			<div>2 collapsing</div>
			<div>3 collapsing</div>
			<div class="float">4A float</div>
			<div>4 collapsing</div>
		</div>
		<div>COLLAPSE ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>COLLAPSE v</div>
		<div class="col cf">
			<div class="float">1A float</div>
			<div>1 collapsing</div>
			<div class="float">2A float</div>
		</div>
		<div>COLLAPSE ^</div>
		<div class="float">3 float</div>
	</section> 

	<section>
		<div>COLLAPSE v</div>
		<div class="col cf">
			<div class="float">1 float</div>
			<div class="float">2 float</div>
			<div class="float">3 float</div>
			<div class="float">4 float</div>
		</div>
		<div>COLLAPSE ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>flow-root v</div>
		<div class="col root">
			<div class="float">1 float</div>
			<div>2 collapsing</div>
			<div class="float">3 float</div>
			<div class="float">4 float</div>
		</div>
		<div>flow-root ^</div>
		<div class="float">5 float</div>
	</section> 

	<section>
		<div>flow-root v</div>
		<div class="col root">
			<div>1 collapsing</div>
			<div class="float">1A float</div>
			<div>2 collapsing</div>
			<div>3 collapsing</div>
			<div>4 collapsing</div>
		</div>
		<div>flow-root ^</div>
		<div class="float">5 float</div>
	</section>

</main>

              
            
!

CSS

              
                @width: 80px;
//@height: 20px;
//@height-collapsing: 50px;
@margin: 20px;


.clearfix {
	&:after {
		clear: both;
		content: '';
		// Margin collapsing is a feature, not a bug, hence relying on `block`.
		display: block;
	}
}

.clearfix( false ) {
	&:after {
		clear: both;
	}
	&:before,
	&:after {
		content: '';
		display: table;
	}
}

.root {
	display: flow-root;
}



.cfnc {
	.clearfix( false );
	//.clearfix-1( false );
	//.clearfix-2( false );
	//.clearfix-3-nocollapse();
	//.clearfix-4-nocollapse();
	//.clearfix-5( false );
	//.clearfix-6( false );
}

.cf {
	.clearfix();
	//.clearfix-1();
	//.clearfix-2();
	//.clearfix-3();
	//.clearfix-4();
	//.clearfix-5();
	//.clearfix-6();
	//.clearfix-noblock();
}




.clearfix-6( @collapse: true ) {
	&:after {
		clear: both;
	
		& when ( @collapse ) {
			content: '';
			display: block;
			// Margin collapsing is a feature, not a bug, hence relying on `block`.
		}
	}

	&:before,
	&:after {
		& when not ( @collapse ) {
			content: '';
			display: table;
		}
	}
}




.clearfix-5:after {
	clear: both;
	content: '';
	// Margin collapsing is a feature, not a bug, hence relying on `block`.
	display: block;
}

.clearfix-5( false ) {
	&:after {
		clear: both;
	}
	&:before,
	&:after {
		content: '';
		display: table;
	}
}




//
// With bool parameter: 13 lines
//
.clearfix-1( @collapse: true ) {
	// Margin collapsing is a feature, not a bug, hence relying on `block`.
	&:after {
		clear: both;
	}

	&:before,
	&:after {
		content: '';
		display: if( @collapse, block, table );
	}
}


//
// With bool parameter and when: 19 lines
// Minimal CSS
//
.clearfix-2( @collapse: true ) {
	&:after {
		clear: both;
		& when ( @collapse ) {
			content: '';
			display: block;
			// Margin collapsing is a feature, not a bug, hence relying on `block`.
		}
	}

	& when not ( @collapse ) {
		&:before,
		&:after {
			content: '';
			display: table;
		}
	}
}

//
// Without parameter: 20 lines
// Minimal CSS
//
.clearfix-3 {
	// Margin collapsing is a feature, not a bug, hence relying on `block`.
	&:after {
		clear: both;
		content: '';
		display: block;
	}
}

.clearfix-3-nocollapse {
	&:after {
		clear: both;
	}
	&:before,
	&:after {    
		content: '';
		display: table;
	}
}


//
// With inheritance: 19 lines
// Unnecessary rule in .clearfix-4-nocollapse: &:after {display: block;}
//
.clearfix-4 {
	// Margin collapsing is a feature, not a bug, hence relying on `block`.
	&:after {
		clear: both;
		content: '';
		display: block;
	}
}

.clearfix-4-nocollapse {
	.clearfix-4();

	&:before,
	&:after {
		content: '';
		display: table;
	}
}


//
// Without display:block: 20 lines
// Collapses margin-BOTTOM even if there is a float element.
//
.clearfix-noblock {
	// Margin collapsing both top and bottom.
	&:after {
		clear: both;
		content: '';
	}
}



//
// Content
//

main {
	display: flex;
}

section {
	/* width: 50%; */
}

div {
	background-color: navajowhite;
	margin: @margin 10px;
}

.float,
div > div {
	box-shadow: inset 0 0 0 1px blue;
	text-align: center;
	width: @width;
}

.float {
	margin: 5px;
	float: right;
	float: left;
	background-color: lightblue;
	//height: @height;
	
	#hidefloats:checked ~ main & {
		display: none;
	}
}

div > div:not(.float) {
	/* display: inline-block; */
	background-color: lightskyblue;
	//height: @height-collapsing;
}

              
            
!

JS

              
                
              
            
!
999px

Console