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

              
                <p class="name">Body</p>
<p class="description">
	<code class="tag">&lt;HTML&gt;</code> is the Stacking order root, followed by <code class="tag">&lt;body&gt;</code>.
</p>

<div class="div div1">
	<span class="name">DIV #1</span>
	<span class="description">Level 1.</span>
	<code class="properties">
		<p>
			<span class="prop">position</span>:
			<span class="val">static</span>;
		</p>
	</code>
</div>

<div class="div div2">
	<span class="name">DIV #2</span>
	<span class="description">
		Element with a <code class="prop">position</code> value <code class="val">absolute</code> or <code class="val">relative</code>, and <code class="prop">z-index</code> value other than <code class="val">auto</code>.<br><br>
		This element is <code class="prop">absolute</code> to the <code class="tag">&lt;BODY&gt;</code>
	</span>
	<code class="properties">
		<p>
			<span class="prop">position</span>:
			<span class="val">absolue</span>;	
		</p>
		<p>
			<span class="prop">z-index</span>:
			<span class="val">0</span>;
		</p>
	</code>
</div>

<div class="div div3">
	<span class="name">DIV #3</span>
	<span class="description">
		Element with a <code class="prop">position</code> value <code class="val">fixed</code> or <code class="val">static</code>.
	</span> 
	<code class="properties">
		<p>
			<span class="prop">position</span>:
			<span class="val">fixed</span>;	
		</p>
	</code>
</div>

<div class="div div4 flex-container">
	<span class="name">DIV #4</span>
	<span class="description">A flex parent.</span>
	<code class="properties">
		<span class="prop">display</span>: <span class="val">flex;</span>
	</code>
	<div class="div div5 flex-item">
		<span class="name">DIV #5</span>
		<span class="description">Element that is a <span class="bold">child</span> of a <code class="val">flex</code> container, with <code class="prop">z-index</code> value other than <code class="val">auto</code>.</span>
		<code class="properties">
			<span class="prop">z-index</span>: <span class="val">0</span>;
		</code>
	</div>
</div>

<div class="div div6 grid-container">
	<span class="name">DIV #6</span>
	<span class="description">A grid parent.</span>
	<code class="properties">
		<span class="prop">display</span>: <span class="val">grid</span>;
	</code>
	<div class="div div7 flex-item">
		<span class="name">DIV #7</span>
		<span class="description">Element that is a <span class="bold">child</span> of a <code class="val">flex</code> container, with <code class="prop">z-index</code> value other than <code class="val">auto</code>.</span>
		<code class="properties">
			<span class="prop">z-index</span>: <span class="val">0</span>;
		</code>
	</div>
</div>

<div class="div div8">
	<span class="name">DIV #8</span>
	<span class="description">Element with an <code class="val">opacity</code> value less than <code class="val">1</code>. (See the <a href="http://www.w3.org/TR/css3-color/#transparency" target="blank">specification for opacity</a>)</span>
	<code class="properties">
		<span class="prop">opacity</span>: <span class="val">0.99</span>;
	</code>
</div>

<div class="div div9">
	<span class="name">DIV #9</span>
	<span class="description">Element with an <code class="prop">mix-blend-mode</code> value other than <code class="val">normal</code>.
		<code class="properties">
			<span class="prop">mix-blend-mode</span>: <span class="val">multiply</span>;
		</code>
	</span>
</div>

<div class="div div10">
	<span class="name">DIV #10</span>
	<span class="description">Element with any of the following properties with value other than <code class="val">none</code>:
		<ul>
			<li><code class="prop">transform</code></li>
			<li><code class="prop">filter</code></li>
			<li><code class="prop">perspective</code></li>
			<li><code class="prop">clip-path</code></li>
			<li>
				<code class="prop">mask</code> / <code class="prop">mask-image</code> / <code class="prop">mask-border</code>
			</li>
		</ul>
		<code class="properties">
			<span class="prop">transform</span>: <span class="val">translate(0)</span>;
		</code>
	</span>
</div>

<div class="div div11">
	<span class="name">DIV #11</span>
	<div class="description">
		Element with a <code class="prop">isolation</code> value <code class="val">isolate</code>.
	</div>
	<code class="properties">
		<span class="prop">isolation</span>: <span class="val">isolate</span>;
	</code>
</div>

<div class="div div12">
	<span class="name">DIV #12</span>
	<span class="description">
		Element with a <code class="prop">-webkit-overflow-scrolling</code> value <code class="val">touch</code>.
	</span>
	<code class="properties">
		<span class="prop">-webkit-overflow-scrolling</span>: <span class="val">touch</span>;
	</code>
</div>

<div class="div div13">
	<span class="name">DIV #13</span>
	<span class="description">
		Element with a <code class="prop">will-change</code> value specifying any property that would create a stacking context on non-initial value (see this <a href="https://dev.opera.com/articles/css-will-change-property/" target="_blank">post</a>).
	</span>
	<code class="properties">
		<span class="prop">will-change</span>: <span class="val">opacity</span>;
	</code>
</div>

<div class="div div14">
	<span class="name">DIV #14</span>
	<span class="description">
		Element with a <code class="prop">contain</code> value of <code class="val">layout</code>, or <code class="val">paint</code>, or a composite value that includes either of them (i.e. <code><span class="prop">contain</span>: <span class="val">strict</span></code>, <code><span class="prop">contain</span>: <span class="val">content</span></code>).
	</span>
	<code class="properties">
		<span class="prop">contain</span>: <span class="val">content</span>;
	</code>
</div>

<label for="toggle-help" class="help">
	<span class="icon">?</span>
	<input type="checkbox" id="toggle-help">
	<div class="popup">
		<ul>
			<li>
				The stacking context of elements used to be simple and easy to understand. Over the years, as new properties and values were introduced into CSS, the stacking order became more complex, and seemingly unpredictable, if not understood correctly.
			</li>
			<li>
				This demo shows the stacking context of a single level (<code class="tag">&lt;BODY&gt;</code> as the stacking context root), and a maximum of one child per element, if needed for the demo purposes.
				
				Details from MDN.<br>For more information, read <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context" target="_blank"> The Stacking Context</a>
			</li>
			<li>
				The CSS mentioned in each div is actually applied to it. In case of multiple possibilities, only one is assigned.<br>
				No <code class="prop">z-index</code> is assigned, unless otherwise mentioned. <br>
				Other styling rules (colors, sizes etc.) are applied but aren't shown in the output. Explore the code for the full style.
			</li>
			<li>
				Click an element to focus it and fade the others.<br>
				Moving the cursor outside of the element will remove the effect.
			</li>
			<li>Click anywhere to close this modal.</li>
		</ul>
	</div>
</label>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&family=Ubuntu+Mono&display=swap');


@function color-to-hsla($color) {
    @return hsla(hue($color), saturation($color), lightness($color), var(--alpha));
}

$base-font-size: 16px;
$divs: 14;
$colors: (
	0: black,
	1: PaleVioletRed,
	2: SpringGreen,
	3: CornflowerBlue,
	4: Khaki,
	5: Plum,
	6: Salmon,
	7: MediumSeaGreen,
	8: Bisque,
	9: Black,
	10: Sienna,
	11: SteelBlue,
	12: PaleVioletRed,
	13: DarkKhaki,
	14: Teal,
);

:root {
	--alpha: 1;
}

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

HTML {
	--font-size: #{$base-font-size};
	font-size: var(--font-size); font-family: 'Montserrat', sans-serif;
	@media (max-width:1024px) {
		--font-size: 14px;
	}
	@media (max-width:900px) {
		--font-size: 12px;
	}
	@media (max-width:700px) {
		--font-size:10px;
	}
}

P {margin: 0.5rem 0;}

BODY, div {
	border: 0.2rem dashed currentColor;
	padding: 0.5rem;
}
BODY {
	min-height: 100vh;
	background: rgba(map-get($colors,0),0.25);
	margin:0.5rem;
	//padding-bottom: 50vh;
	font-size:1rem;
}

A {
	text-decoration:none;
	color: color-to-hsla(DodgerBlue);
}

code {
	background: color-to-hsla(#333);
	color:color-to-hsla(#fff);
	padding: 0.5rem 0.5rem;
	border-radius: 0.25rem;
	display: inline-flex;
	flex-direction:column;
	line-height: 1.35;
	font-family: 'Ubuntu Mono', monospace;
	.description &, .help & {
		padding: 0.125rem 0.5rem;
		border-radius: 0.25rem;
		flex-direction:row;
	}
	p {
		margin: 0;
	}
}

.bold {font-weight:bold;}

.tag { color:orange; }
.prop { color:color-to-hsla(magenta); }
.val { color:color-to-hsla(cyan); }

.name {font-weight:bold;}

.description {
	display: block; margin-top: 4px;
}
.properties {
	display:block;
	margin-top: 1rem;
}

.div {
	margin: 1.5rem 0.25rem;
	transition:0.2s opacity ease-in-out;	
		margin-top: 1rem;
	
	@for $i from 1 through $divs {
		&#{$i} {
			$bgColor: color-to-hsla(darken(map-get($colors,$i),15));
			border-color:color-to-hsla(map-get($colors, $i));
			color:color-to-hsla(ghostwhite);
			background-color: $bgColor;			
			box-shadow: 0 0 0 0.3rem $bgColor;
			.description code {
				border: 1px solid $bgColor;
			}
		} 
	}
	
	&1 {
		margin-top: 2rem;
		padding-bottom: 3rem;
	}
	&2 {
		position:absolute;
		top:5rem;
		left:15rem;
		// height: 15rem;
		z-index:0;
		.properties {
			margin-bottom: 1rem;
		}
	}
	&3 {
		position: fixed;
		height: 35rem;
		left: 27rem;
		top:14rem;
	}
	&4, &8 {
		color:color-to-hsla(#222);
	}
	&4 {
		display:flex;
		flex-direction:column;
	}
	&5 { z-index:0; }
	&6{
		display: grid;
	}
	&7 {
		z-index:0;
	}
	&8 {
		opacity: 0.99;
	}
	&9 {
		border-color:color-to-hsla(ghostwhite);
		mix-blend-mode: multiply;
		z-index:1;
	}
	&10 {
		transform:translate(0);
	}
	&11 {
		isolation:isolate;
	}
	&12 {
		-webkit-overflow-scrolling: touch;
	}
	&13 {
		will-change:opacity;
	}
	&14 {
		contain:content;
	}
	
	
	&.fade {
		--alpha: 0.2;
	}
	&.nofade {
		--alpha: 1;
	}
}

.help {
	position:fixed;
	bottom: 2vmax;
	right: 2vmax;
	width: 3rem;
	height: 3rem;
	border-radius:50%;
	background: white;
	display:flex;
	align-items: center;
	justify-content: center;
	cursor:pointer;
	&::before, &::after {
		content: '';
		width: 100%;
		height: 100%;
		border: 0.2rem solid white;
		border-radius:50%;
		position: absolute;
		top: 50%;
		left: 50%;
		transform:translate(-50%,-50%);
		animation: ripple 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
	}
	&::after {
		animation-delay:0.75s;
	}
	.icon {
		font-family: 'Ubuntu Mono', monospace;
		font-size: 2.5rem;
	}
	.popup {
		border: 2px solid white;
		background: #333;
		color:white;
		border-radius: 0.25rem;
		box-shadow: 0 0 0 0.15rem #fff,
			0 0 1rem #333;
		line-height: 1.5;
		transform-origin: bottom right;
		position: absolute;
		bottom: 0;
		right: 0;
		width: 80vw;
		transform:translate(-3rem, -3rem);
		display:none;
		UL {
			padding-left:1rem;
		}
		LI {
			margin-bottom: 1rem;
		}
	}
	
	input[type="checkbox"] {
		display:none;
		&:checked + .popup {
			display:block;
		}
	}
}

@keyframes ripple {
	from { width: 100%; height: 100%; }
	to {width:200%; height: 200%; border-color:transparent;}
}
              
            
!

JS

              
                $('.div').on('click',function(e) {
	e.stopPropagation();
	$(this).addClass('nofade');
	$('div').not($(this)).addClass('fade');
}).on('mouseleave',function(){
	$('div').removeClass('fade nofade')
})
              
            
!
999px

Console