Pen Settings

HTML

CSS

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

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

              
                <div class="buttons" style="width: fit-content; height: fit-content; padding: 15px 10px; background: #e8f0fe; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); border-radius: 5px;">
	<div class="button1 cooltool" data-tooltip-dir="top" data-content-before="bordered" data-content-after="bye" data-tooltip-border="true" style="padding: 5px 10px; border-radius: 5px; display: inline-block; margin: 10px; cursor: pointer; background: #5291ff; color: #fff;">
	top
	</div>
	<div class="button1 cooltool" data-tooltip-dir="right" data-content-before="If you want your tooltip aligned with the top of the element rather than centered by the element, just add the attribute: 'data-align=top'. This works on left and right tooltips." data-content-after="bye" data-align="top" style="padding: 5px 10px; border-radius: 5px; display: inline-block; margin: 10px; cursor: pointer; background: #5291ff; color: #fff;">
	right
	</div>
	<div class="button1 cooltool" data-tooltip-dir="bottom" data-content-before="content will stay on click" data-content-after="but revert on mouseleave"  data-keep-after="true" style="padding: 5px 10px; border-radius: 5px; display: inline-block; margin: 10px; cursor: pointer; background: #5291ff; color: #fff;">
	bottom
	</div>
	<div class="button1 cooltool" data-tooltip-dir="left" data-content-before="this only has one content attribute" style="padding: 5px 10px; border-radius: 5px; display: inline-block; margin: 10px; cursor: pointer; background: #5291ff; color: #fff;">
	left
	</div>
</div>

<button class="goto btn" style="position: absolute; bottom: 10px; left: 10px; background: #e8f0fe;"><a href="https://codepen.io/Souleste/pen/qBWmVwQ" target="_blank">demo usage</a></button>

              
            
!

CSS

              
                /* add this to your css files in codepen */

/* change this color for personalized borders */
:root {
	--tool-border: red;
}
.cooltool {
	position: relative;
	cursor: pointer;
}
.tooltip {
	opacity: 0;
	color: #fff;
	background: rgba(0,0,0,0.8);
	position: absolute;
	border-radius: 5px;
	padding: 0px 10px 3px 10px;
	transition: 0.3s;
	transition-delay: 0.1s;
	pointer-events: none;
	max-width: 200px;
	width: max-content;
	z-index: 9999;
}
.tooltip::after {
	color: rgba(0,0,0,0.8);
	position: absolute;
}
.tooltip .after-content {
	display: none;
}
.cooltool:hover .tooltip {
	opacity: 1 !important;
}
.tooltip .hideTip {
	display: none;
}
.tooltip .showTip {
	display: block;
}

/* left tooltip */
.cooltool:hover [data-tooltip="left"] {
	right: calc(100% + 15px);
	transform: translate(0,-50%);
}
[data-tooltip="left"] {
	top: 50%;
	right: 50%;
	transform: translate(0,-50%);
}
[data-tooltip="left"]::after {
	top: 50%;
	right: -7px;
	transform: translate(0, -50%);
	border-left: 7px solid rgba(0,0,0,0.8);
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  content: '';
}
[data-tooltip-dir="left"][data-align="top"] .tooltip {
	transform: translate(0,0) !important;
	top: 0 !important;
}
[data-tooltip-dir="left"][data-align="top"] .tooltip::after {
	transform: translate(0,0) !important;
	top: 5px !important;
}


/* bottom tooltip */
.cooltool:hover [data-tooltip="bottom"] {
	top: calc(100% + 15px);
	transform: translate(50%,0);
}
[data-tooltip="bottom"] {
	top: 50%;
	right: 50%;
	transform: translate(50%,0%);
}
[data-tooltip="bottom"]::after {
	top: -6px;
	right: 50%;
	transform: translate(50%, 0);
	border-bottom: 6px solid rgba(0,0,0,0.8);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  content: '';
}

/* right tooltip */
.cooltool:hover [data-tooltip="right"] {
	left: calc(100% + 15px);
	transform: translate(0,-50%);
}
[data-tooltip="right"] {
	top: 50%;
	left: 50%;
	transform: translate(0,-50%);
}
[data-tooltip="right"]::after {
	top: 50%;
	left: -7px;
	transform: translate(0, -50%);
	border-right: 7px solid rgba(0,0,0,0.8);
  border-bottom: 7px solid transparent;
  border-top: 7px solid transparent;
  content: '';
}
[data-tooltip-dir="right"][data-align="top"] .tooltip {
	transform: translate(0,0) !important;
	top: 0 !important;
}
[data-tooltip-dir="right"][data-align="top"] .tooltip::after {
	transform: translate(0,0) !important;
	top: 5px !important;
}

/* top tooltip */
.cooltool:hover [data-tooltip="top"] {
	bottom: calc(100% + 15px);
	transform: translate(50%,0);
}
[data-tooltip="top"] {
	bottom: 50%;
	right: 50%;
	transform: translate(50%,0);
}
[data-tooltip="top"]::after {
	bottom: -6px;
	right: 50%;
	transform: translate(50%, 0);
  border-top: 6px solid rgba(0,0,0,0.8);
  border-right: 6px solid transparent;
  border-left: 6px solid transparent;
  content: '';
}


/*tooltip borders*/
[data-tooltip-border*="true"] .tooltip {
	border: 1px solid var(--tool-border);
}
[data-tooltip-border*="true"] .tooltip .before-content::after, [data-tooltip-border*="true"] .tooltip .after-content::after, [data-tooltip-border*="true"] .tooltip .before-content::before, [data-tooltip-border*="true"] .tooltip .after-content::before {
	content: '';
	display: block;
	height: 2px;
	background: var(--tool-border);
	width: 10px;
	position: absolute;
}

/* left tooltip border */
[data-tooltip-dir*="left"][data-tooltip-border*="true"] .tooltip .before-content::before, [data-tooltip-dir*="left"][data-tooltip-border*="true"] .tooltip .after-content::before{
	top: calc(50% - 5px);
	right: -9px;
	transform: translate(0, 50%) rotate(45deg);
}
[data-tooltip-dir*="left"][data-tooltip-border*="true"] .tooltip .before-content::after, [data-tooltip-dir*="left"][data-tooltip-border*="true"] .tooltip .after-content::after{
	bottom: calc(50% - 3px);
	right: -9px;
	transform: translate(0, 50%) rotate(-45deg);
}

/* bottom tooltip border */
[data-tooltip-dir*="bottom"][data-tooltip-border*="true"] .tooltip .before-content::before, [data-tooltip-dir*="bottom"][data-tooltip-border*="true"] .tooltip .after-content::before{
	width: 9px !important;
	left: calc(50% - 7px);
	top: -6px;
	transform: translate(0, 50%) rotate(-45deg);
}
[data-tooltip-dir*="bottom"][data-tooltip-border*="true"] .tooltip .before-content::after, [data-tooltip-dir*="bottom"][data-tooltip-border*="true"] .tooltip .after-content::after{
	width: 9px !important;
	right: calc(50% - 7px);
	top: -6px;
	transform: translate(0, 50%) rotate(45deg);
}

/* right tooltip border */
[data-tooltip-dir*="right"][data-tooltip-border*="true"] .tooltip .before-content::before, [data-tooltip-dir*="right"][data-tooltip-border*="true"] .tooltip .after-content::before{
	top: calc(50% - 5px);
	left: -9px;
	transform: translate(0, 50%) rotate(-45deg);
}
[data-tooltip-dir*="right"][data-tooltip-border*="true"] .tooltip .before-content::after, [data-tooltip-dir*="right"][data-tooltip-border*="true"] .tooltip .after-content::after{
	bottom: calc(50% - 3px);
	left: -9px;
	transform: translate(0, 50%) rotate(45deg);
}

/* top tooltip border */
[data-tooltip-dir*="top"][data-tooltip-border*="true"] .tooltip .before-content::before, [data-tooltip-dir*="top"][data-tooltip-border*="true"] .tooltip .after-content::before{
	width: 9px !important;
	left: calc(50% - 7px);
	bottom: -4px;
	transform: translate(0, 50%) rotate(45deg);
}
[data-tooltip-dir*="top"][data-tooltip-border*="true"] .tooltip .before-content::after, [data-tooltip-dir*="top"][data-tooltip-border*="true"] .tooltip .after-content::after{
	width: 9px !important;
	right: calc(50% - 7px);
	bottom: -4px;
	transform: translate(0, 50%) rotate(-45deg);
}
              
            
!

JS

              
                // add this to your javascript files in codepen 

	// when dynamically creating something with a tool-tip, just call this function: 
	function setCoolTool() {
		var cooltool = $('.cooltool');
	
		cooltool.each(function() {
			var el = $(this);
			if(!el.find('.tooltip').length > 0) {
				el.append('<span class="tooltip" data-tooltip="'+el.attr('data-tooltip-dir')+'"><span class="before-content">'+el.attr('data-content-before').replace(/\/n/g, "<br>")+'</span><span class="after-content">'+el.attr('data-content-after')+'</span></span>');
			}
		});

		$(document).on('click', '.cooltool', function() {
			var el = $(this);
			var tool = $(this).find('.tooltip');
			var b = el.find('.before-content');
			var a = el.find('.after-content');
			if (el.attr('data-content-after') != undefined) {
				if (el.attr('data-keep-after') == 'true' || el.attr('data-keep-after') == '') {
					a.addClass('showTip');
					b.addClass('hideTip');
				} else {
					function changeContent() {
						b.addClass('hideTip').delay(1200).queue(function(next){
							b.removeClass('hideTip');
							next();
						});
						a.addClass('showTip').delay(1200).queue(function(next){
							a.removeClass('showTip');
							next();
						});
					} changeContent();
				}
			}
		});

		$(document).on('mouseleave', '.cooltool', function() {
			console.log('touchend');
			var el = $(this);
			var b = el.find('.before-content');
			var a = el.find('.after-content');
			function revertChange() {
				a.delay(300).queue(function(next){
					a.addClass('hideTip').removeClass('showTip');
					a.removeClass('hideTip');
					next();
				});
				b.delay(300).queue(function(next){
					b.addClass('showTip').removeClass('hideTip');
					b.removeClass('showTip');
					next();
				});
			} revertChange();
		});
		
	} setCoolTool();
	
	
// 	$(document).on('touchend', '.cooltool', function() {
// 		var el = $(this);
// 		var b = el.find('.before-content');
// 		var a = el.find('.after-content');
// 		var tool = el.find('.tooltip');
// 		function revertChange() {
// 			a.addClass('showTip');
// 			a.delay(1000).queue(function(next){
// 				a.removeClass('showTip');
// 				next();
// 			});
// 			b.delay(1000).queue(function(next){
// 				b.removeClass('hideTip');
// 				next();
// 			});
// 			tool.delay(700).queue(function(next){
// 				tool.css('opacity', 0);
// 				next();
// 			});
			
// 		} revertChange();
// 		$('body').dispatchEvent($(document).on('click', function() {}));
// 	});
	

              
            
!
999px

Console