cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              div.editor
	div.editor-toolbar
		- var colors = ["Black", "Red", "Yellow", "Blue", "Green", "Orange", "Cyan", "Magenta", "Purple", "Gray"]
		button#btnFontColor.toolbar-item(title="Font color")
			i.icon.ms-Icon.ms-StackedIcon
				i.ms-Icon.ms-Icon--FontColorSwatch.color-indicator
				i.ms-Icon.ms-Icon--FontColorA
			ul#menuFontColorSwatch.swatch
				for color in colors
					li.swatch-item(class=color title=color value=color)
		button#btnHighlightColor.toolbar-item(title="Highlight color")
			i.icon.ms-Icon.ms-StackedIcon
				i.ms-Icon.ms-Icon--HighlightFill.color-indicator
				i.ms-Icon.ms-Icon--Highlight
			ul#menuHighlightColorSwatch.swatch
				for color in colors
					li.swatch-item(class=color title=color value=color)
	textarea.editor-textarea Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vitae ligula efficitur, convallis mi vitae, interdum ex. Praesent massa velit, ullamcorper vehicula nunc id, convallis euismod ex. Sed pretium orci dapibus, condimentum metus ut, egestas ex. Maecenas eget erat egestas, pretium nisl eget, pretium eros. Nullam sit amet volutpat nisi, et aliquam ipsum. Aenean vehicula feugiat metus, vel fringilla turpis fringilla non. Integer tristique rhoncus purus quis tincidunt. Vivamus vitae justo lacinia, convallis orci in, congue velit. Vestibulum scelerisque velit vitae leo laoreet, et mattis leo semper. Praesent et nisl eu nisl ornare sollicitudin in non diam. Donec auctor tempor libero sed viverra.
		
            
          
!
            
              html,
body {
	font-family: Segoe UI, Frutiger, Frutiger Linotype, Dejavu Sans, Helvetica Neue,
		Arial, sans-serif;
	font-size: 16px;
	margin: 0;
	padding: 0;
}

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

.ms-Icon {
	font-size: 1rem;
	color: #333;
}

button {
	background: none;
	border: none;
	outline: none;
	padding: 0;
	margin: 0;
	&:hover,
	&:active,
	&:focus,
	&.active {
		background-color: #eaeaea;
	}
}

.editor {
	max-width: 600px;
	margin: 10vh auto;
}

.editor-toolbar {
	background: #f4f4f4;
	height: 40px;
	width: auto;
	display: flex;
	flex-direction: row;
	justify-content: flex-start;
}

.toolbar-item {
	height: 40px;
	width: 40px;
	line-height: 40px;
	position: relative;
}

.ms-StackedIcon {
	position: relative;
	width: inherit;
	height: inherit;

	.ms-Icon {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
	}
}

.editor-textarea {
	width: 100%;
	height: 400px;
	border: 1px solid #eaeaea;
	resize: none;
	outline: none;
	color: Black;
	&::selection {
		background: Yellow;
	}
}

.swatch {
	position: absolute;
	border: 1px solid #eaeaea;
	top: 100%;
	left: 0;
	list-style: none;
	padding: 0;
	margin: 0;
	display: none;
	flex-flow: wrap;
	width: 192px;
	background-color: #fff;
	&.active {
		display: flex;
	}
}

$colors: Black Red Yellow Blue Green Orange Cyan Magenta Purple Gray;

.swatch-item {
	width: 30px;
	height: 30px;
	margin: 4px;
	border: 1px solid #eaeaea;
	&:hover,
	&:focus,
	&:active,
	&.active {
		border: 1px solid #666666;
		box-shadow: inset 0 0 0 2px #eaeaea;
	}
	@each $color in $colors {
		&.#{$color} {
			background-color: $color;
		}
	}
}

@each $color in $colors {
	.color-#{$color} {
		color: $color;
	}
	.selection-#{$color} {
		&::selection {
			background: $color;
		}
	}
}

            
          
!
            
              // Select color
$('.swatch-item').on('click', (e) => {
	const trigger = e.currentTarget;
	const swatchItems = $('.swatch-item');
	const toolbarItem = $(trigger).closest('.toolbar-item');
	const toolbarItemId = $(toolbarItem).attr('id');
	const toolbarIcon = $(toolbarItem).find('.color-indicator');
	const textarea = $('.editor-textarea');
	const selectedColor = $(trigger).attr('value');
	
	// Clear previous selection
	$(swatchItems).removeClass('active');
	
	// Change focus
	$(trigger).addClass('active');
	
	// Change icon color
	$(toolbarIcon).css('color', selectedColor);
	
	// Change textarea font color
	if(toolbarItemId === 'btnFontColor') {
		$(textarea).removeClass((index, className) => (
			(className.match(/color-[A-Z].+\b/g) || []).join(' ')
		)).addClass(`color-${selectedColor}`);
	}
	
	// Change textarea highlight color
	if(toolbarItemId === 'btnHighlightColor') {
		$(textarea).removeClass((index, className) => {
			(className.match(/selection-[A-Z].+\b/g) || []).join(' ')
		}).addClass(`selection-${selectedColor}`);
	}
});

// Toggle swatch
$('.toolbar-item').on('click', (e) => {
	const trigger = e.currentTarget;
	const currentSwatch = $(trigger).find('.swatch');
	$(currentSwatch).toggleClass('active');
});

// Click out to dismiss swatch
$(document).on('click', (e) => {
	const trigger = e.target;
	const closestButton = $(trigger).closest('button');
	if ($(closestButton).attr('id') !== 'btnFontColor') {
		const fontColorSwatch = $('#btnFontColor .swatch');
		$(fontColorSwatch).removeClass('active')
	}
	if ($(closestButton).attr('id') !== 'btnHighlightColor') {
		const highlightColorSwatch = $('#btnHighlightColor .swatch');
		$(highlightColorSwatch).removeClass('active');
	}
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console