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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              p.serif Change the input below and see how the placeholder avatar reacts.

div.form
	input.js-input(input='text', value='Jerry Primrose')
	a.btn.js-submit Submit

div.person
	div
		div.person-avatarPlaceholder.color-1.js-avatarPlaceholder
			span.js-initials JP
	div.person-name.js-name Jerry Primrose
	
            
          
!
            
              $black: #4f4f4f;
$red:   #d9566f;
$blue:  #56bcd9;
$green: #7fbb15;

/* Relevant Code */
.person {
	display: table;
	margin: 24px auto;
	> * {
		display: table-cell;
		vertical-align: middle;
	}
}
.person-avatarPlaceholder {
	width: 48px;
	height: 48px;
	border-radius: 50%;
	border: 2px solid;
	&.color-0 {
		color: $red;
		background: rgba($red, 0.15);
	}
	&.color-1 {
		color: $blue;
		background: rgba($blue, 0.15);
	}
	&.color-2 {
		color: $green;
		background: rgba($green, 0.15);
	}
	line-height: 46px;
	text-align: center;
}
.person-name {
	padding-left: 12px;
}

/* Style */
* {
	box-sizing: border-box;
}
body {
	color: $black;
	font-size: 18px;
	font-family: "Helvetica Neue", "Segoe UI", "Roboto", sans-serif;
	padding: 24px;
	text-align: center;
}
input {
	-webkit-appearance: none;
	border-radius: 0;
	border: 1px solid $black;
	font: inherit;
	height: 32px;
	line-height: 32px;
	padding: 0 8px;
	margin: 0;
	&:focus {
		outline: none;
	}
	+ .btn {
		margin-left: -1px;
	}
}
.btn {
	cursor: pointer;
	display: inline-block;
	vertical-align: top;
	height: 32px;
	line-height: 32px;
	padding: 0 8px;
	border: 1px solid $black;
	background: linear-gradient(to bottom, white 0%, #eee 100%);
	&:hover {
	    background: linear-gradient(to bottom, white 0%, #ddd 100%);
	}
}
.form {
	display: table;
	margin: 0 auto;
	> * {
		float: left;
	}
	zoom: 1;
	&:before,
	&:after {
		content: ".";
		display: block;
		height: 0;
		overflow: hidden;
	}
	&:after {
		clear: both;
	}
}
.serif {
	font-family: Georgia, serif;
	margin-bottom: 24px;
}
@media (max-width: 767px) {
	body {
		font-size: 15px;
	}
}
            
          
!
            
              String.prototype.hashCode = function() {
			var hash = 0,
						i, chr, len;
			if (this.length == 0) return hash;
			for (i = 0, len = this.length; i < len; i++) {
						chr = this.charCodeAt(i);
						hash = ((hash << 5) - hash) + chr;
						hash |= 0; // Convert to 32bit integer
			}
			return hash;
};

String.prototype.getInitials = function(glue) {
			if (typeof glue == "undefined") {
						var glue = true;
			}

			var initials = this.replace(/[^a-zA-Z- ]/g, "").match(/\b\w/g);

			if (glue) {
						return initials.join('').substring(0, 2);
			}

			return initials.substring(0, 2);
};

var numColors = 3;

$('.js-submit').click(function() {
			var initials = $('.js-input').val().getInitials();
			var hash = Math.abs($('.js-input').val().hashCode()) % numColors;
			$('.js-initials').text(initials);
			$('.js-name').text($('.js-input').val());
			$('.js-avatarPlaceholder').removeClass('color-0').removeClass('color-1').removeClass('color-2').addClass('color-' + hash);
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console