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

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>Using <code>:is()</code> in complex selectors selects more than you might initially think</h1>

<p><em>Demo for <a href="https://brm.us/css-is-matching" target="_top">https://brm.us/css-is-matching</a></em></p>

<h2>Demo</h2>

<label for="selector">Selector</label>
<select name="selector" id="selector">
	<option value="">Choose</option>
	<option value=".a .b .c">.a .b .c</option>
	<option value=".a :is(.b .c)">.a :is(.b .c)</option>
</select>

<div id="demo">
	
	<div class="a">
		<div class="b">
			<div class="c"></div>
		</div>
	</div>

	<div class="b">
		<div class="a">
			<div class="c"></div>
		</div>
	</div>
</div>
              
            
!

CSS

              
                .match {
	background: green !important;
}


#demo div {
	background: rgb(0 0 0 / 0.25);
	text-align: center;
	padding: 1em;
	width: min-content;
	border: 1px solid #333;
	position: relative;
}

#demo div::before {
	content: '.' attr(class);
	position: absolute;
	top: 0;
	left: 0;
}

#demo .c {
	aspect-ratio: 1;
	width: 5em;
}

#demo {
	display: flex;
	flex-direction: column;
	justify-content: space-around;
	align-items: center;
	margin: 1em 0;
	gap: 1em;
}
@media (min-width: 500px) {
	#demo {
		flex-direction: row;
	}
}

/* Non-demo styles below */
@layer base {
	@layer layout {
		html {
			max-width: 84ch;
			padding: 3rem 2rem;
			margin: auto;
			line-height: 1.5;
			font-size: 1.25rem;
		}
		body {
			margin: 0;
			padding: 0;
		}
		a,
		a:visited {
			color: blue;
		}
		
		h2 {
			margin-top: 2em;
		}
	}
	
	@layer code {
		pre {
			border: 1px solid #dedede;
			padding: 1em;
			background: #f7f7f7;
			font-family: "Courier 10 Pitch", Courier, monospace;
			overflow-x: auto;
			border-left: 0.4em solid cornflowerblue;
			tab-size: 4;
		}
		
		code:not(pre code) {
			background: #f7f7f7;
			border: 1px solid rgb(0 0 0 / 0.2);
		}
	}

	@layer support {
		.no-support,
		.has-support {
			margin: 1em 0;
			padding: 1em;
			border: 1px solid #ccc;
		}

		.no-support {
			background-color: #ff00002b;
			display: block;
		}
		.no-support[data-level="warn"] {
			background-color: #ffff002b;
		}
		.has-support {
			background-color: #00ff002b;
			display: none;
		}
		:is(.has-support, .no-support) > :first-child {
			margin-top: 0;
		}
		:is(.has-support, .no-support) > :last-child {
			margin-bottom: 0;
		}

		@supports selector(:has(*)) {
			.no-support[data-support="css-has-basic"] {
				display: none;
			}
			.has-support[data-support="css-has-basic"] {
				display: block;
			}
		}

		@supports selector(:has(+ *)) {
			.no-support[data-support="css-has-relative"] {
				display: none;
			}
			.has-support[data-support="css-has-relative"] {
				display: block;
			}
		}

		@supports selector(:nth-child(1 of .foo)) {
			.no-support[data-support="css-nth-child-of-s"] {
				display: none;
			}
			.has-support[data-support="css-nth-child-of-s"] {
				display: block;
			}
		}
	}
}

@layer reset {
	
}
              
            
!

JS

              
                const $targetDivs = document.querySelectorAll('#demo .c');
	
document.querySelector('#selector').addEventListener('change', e => {	
	const selector = e.target.value ? e.target.selectedOptions[0].value : '#fake';
	
	$targetDivs.forEach($div => {
		if ($div.matches(selector)) {
			$div.classList.add('match');
		} else {
			$div.classList.remove('match');
		}
	});
	
});
              
            
!
999px

Console