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

              
                <main>
	<div class="center">
		<h1>Tooltip</h1>
		<p>
			A tooltip that uses CSS animations to animate in & out.
			<span class="tooltip-wrap">
				<button class="btn btn-link tooltip-trigger" data-tooltip-trigger>Red-eyed Tree Frog</button>
				<span class="tooltip" data-tooltip>
					The red-eyed tree frog flashes its brightly colored body parts when startled. It is also called the red-eyed leaf frog. They are nocturnal hunters that use keen eyesight to find prey.
					<a href="http://animals.nationalgeographic.com/animals/amphibians/red-eyed-tree-frog/">http://animals.nationalgeographic.com/animals/amphibians/red-eyed-tree-frog/</a>
				</span>
			</span>
			quod, dolor sequi, similique commodi quam temporibus aperiam, amet reprehenderit nulla quo saepe veritatis libero!
		</p>
		<p>
			Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus facilis ipsa officia, quasi veritatis eos rem explicabo minus ea enim?
		</p>
	</div>
</main>
              
            
!

CSS

              
                /* ==========================================================================
   $Variables
   ========================================================================== */

/* $Colors
   ========================================================================== */
$yellow:				#F0BF19;
$orange:				#EF602C;
$orange--dark:			darken($orange, 10%);
$green:					#0FC03E;
$green--dark:			#0DA836;

$color-bg:				$orange--dark;
$color-bg:				$orange--dark;
$color-primary:			$green;
$color-primary--dark:	$green--dark;
$color-accent:			$yellow;

/* $Type
   ========================================================================== */
$base-font-size: 20px;
$base-scale:     1.4;
$base-rhythm:    ceil($base-font-size * $base-scale);

/* $Fonts
   ========================================================================== */
$font-primary: 'Titillium Web', sans-serif;




/* ==========================================================================
   $Mixins
   ========================================================================== */

/* $Baseline
   ========================================================================== */
@mixin show-baseline($base: $base-font-size, $baseline: $base-scale, $rhythm: $base-rhythm, $color: dodgerBlue, $opacity: 0.75) {
        
    $rhythm: $rhythm + 0px;

    background-image: repeating-linear-gradient(to bottom, rgba($color, $opacity), rgba(white, 0) 1px, rgba(white, 0));
    background-size: 100% $rhythm;
}




/* ==========================================================================
   $Setup
   ========================================================================== */
body {
	background-color: $color-bg;
	color: #fff;
	font: 300 20px/1.43 $font-primary;
}

main {
	display: flex;
	align-items: center;
	height: 100vh;
	justify-content: center;
}

	.center {
		// @include show-baseline($color: #fff, $opacity: 1);
		max-width: 62%;
	}

/* $Typography
   ========================================================================== */
h1 {
	font: 700 39px/56px $font-primary;
	margin: 28px 0;
}

p { margin: 0 0 28px; }

%link-styles {
	color: $color-primary;
	border-bottom: 1px dotted $color-primary;
	font-weight: 700;
}

a { @extend %link-styles; }


/* ==========================================================================
   $Buttons
   ========================================================================== */
.btn {
	background-color: transparent;
	border: 0;
	display: inline-block;
}

	.btn-link {
		@extend %link-styles;
		border-bottom: 1px dotted;
	}




/* ==========================================================================
   $Tooltip
   ========================================================================== */
.tooltip-wrap {
	display: inline-block;
	max-width: 100%;
	position: relative;
}

	/**
	 * 1. Drop-shadow allows the shadow to cover 
	 * 	  everything including the triangle vs box-shadow
	 */
	
	.tooltip {
		background-color: $color-primary;
		display: block;
		filter: drop-shadow(0 2px 8px rgba(black, 0.4)); /* 1 */
		font-size: 14px;
		padding: 1.4em;
		position: absolute;
		bottom: 145%;

		&:before {
			content: '';
			border: 15px solid transparent;
			border-top-color: $color-primary;
			position: absolute;
			left: 2.8em;
			top: 100%
		}

	}

		.tooltip a { color: inherit; }

	.tooltip-in {
		animation:	fade-in 0.20s ease-in-out forwards,
					tooltip-in 0.25s ease-in-out forwards;
	}

	.tooltip-out {
		animation:	fade-in 0.20s ease-in-out forwards reverse,
					tooltip-out 0.25s ease-in-out forwards;
	}




/* ==========================================================================
   $Animations
   ========================================================================== */
@keyframes fade-in {

	from { opacity: 0; }

	to { opacity: 1; }

}

@keyframes tooltip-in {

	0% { transform: translateY(100%); }

	25% { transform: translateY(-15%); }

	35% { transform: translateY(5%) }

	45% { transform: translateY(-3%); }

	55% { transform: translateY(2%); }

	65% { transform: translateY(-2%); }

	100% { transform: translateY(0); }

}

@keyframes tooltip-out {

	0% { transform: translateY(0); }

	25% { transform: translateY(5%) }

	100% { transform: translateY(100%) }

}
              
            
!

JS

              
                var animEndEventNames = {

	'WebkitAnimation' : 'webkitAnimationEnd',
	'OAnimation' : 'oAnimationEnd',
	'msAnimation' : 'MSAnimationEnd',
	'animation' : 'animationend'

};

var animEndEventName = animEndEventNames[Modernizr.prefixed('animation')];


function initTooltip() {

	var $trigger	= $('[data-tooltip-trigger]'),
		$tooltip	=  $trigger.next('[data-tooltip]');

	// Hide tooltips
	$tooltip.hide();

	$('[data-tooltip-trigger]').on('click', function(e) {

		var self = $(this);

		e.preventDefault();

		if ( !self.hasClass('active') ) {

			self.addClass('active');
			self
				.next()
				.show()
				.addClass('tooltip-in')
				.on(animEndEventName, function() {
					$(this).removeClass('tooltip-in').show();
				});

		} else {

			closeTooltip();

		}

		$('body').on('click', function() {

			if ( !$(event.target).closest($trigger).length ) {

				if ( $trigger.hasClass('active') ) {

					closeTooltip();

				}

			}

		});


	});

	function closeTooltip() {

		$trigger.removeClass('active');
		$tooltip
			.addClass('tooltip-out')
			.on(animEndEventName, function() {
				$(this).removeClass('tooltip-out').hide();
			});

	}

}

initTooltip();
              
            
!
999px

Console