cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-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.

            
              <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>
            
          
!
            
              /* ==========================================================================
   $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%) }

}
            
          
!
            
              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
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