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 class="namespace">
    <h2>$('container.selector').tooltip()</h2>
    <small>Fully accessible tooltip jQuery plugin with delegation.</small>
    <p>Delegate tooltip binding to <code>body</code> or other view container(s) as needed.<br />Ideal for restricting event listening to view containers that re-render content.</p>
    <table>
        <tr>
            <td>
                <button type="button">+
                    <span class="tooltip tip-bottom-right" role="tooltip">Tip: bottom-right</span>
                </button>
            </td>
            <td>
                <button type="button">+
                    <span class="tooltip tip-bottom" role="tooltip">Tip: bottom<br />This is the default.</span>
                </button>
            </td>
            <td>
                <button type="button">+
                    <span class="tooltip tip-bottom-left" role="tooltip">Tip: bottom-left</span>
                </button>
            </td>
        </tr>
        <tr>
            <td>
                <button type="button">+
                    <span class="tooltip tip-right" role="tooltip">Tip: right</span>
                </button>
            </td>
            <td>
                <span>&nbsp;</span>
            </td>
            <td>
                <button type="button">+
                    <span class="tooltip tip-left" role="tooltip">Tip: left</span>
                </button>
            </td>
        </tr>
        <td>
            <button type="button">+
                <span class="tooltip tip-top-right" role="tooltip">Tip: top-right</span>
            </button>
        </td>
        <td>
            <button type="button">+
                <span class="tooltip tip-top" role="tooltip">Tip: top</span>
            </button>
        </td>
        <td>
            <button type="button">+
                <span class="tooltip tip-top-left" role="tooltip">Tip: top-left</span>
            </button>
        </td>
    </table>
</main>
              
            
!

CSS

              
                html {
    font-size: 62.5%;
}
body {
    font-family: Calibri, Candara, Segoe, 'Segoe UI', Optima, Arial, sans-serif;
    font-size: 1.6em;
}
main {
    margin: 1em;
    text-align: center;
}
h2 {
    margin: 0 0 1em;
    font-size: 2.4rem;
    line-height: 1;
    text-align: center;
}
table {
    table-layout: fixed;
    border-collapse: collapse;
    margin: 0 auto;
    padding: 0;
    border: none;
}
td {
    padding: .2em;
}
button {
    /* Tooltip parent must have these base styles */
    position: relative;
    overflow: visible;
}

/* Tooltip shared base styles */
.tooltip {
    position: absolute;
    z-index: 2;
    overflow: hidden;
    clip: rect(0,0,0,0);
    box-sizing: border-box;
    width: 0;
    height: 0;
    padding: 0;
    cursor: default;
    color: #fff;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 14px;
    font-size: 1.4rem;
    line-height: normal;
    text-align: center;
    white-space: nowrap;
    border-width: 0;
    border-style: solid;
    border-color: #6d6e71;
    border-top-color: #373739;
    background-color: #373739;
    opacity: 0;
    transition: opacity .3s ease-in .3s;
}

/* Tooltip visibility class toggled by jQuery */
.tooltip.isVisible {
    overflow: visible;
    clip: auto;
    width: auto;
    height: auto;
    padding: 10px 15px;
    border-width: 1px;
    opacity: 1;
}

/* Tooltip positioning */
/** Common styles: Horizontally Centered **/
.tooltip, /*** Default is equivalent to .tip-bottom ***/
.tooltip.tip-bottom,
.tooltip.tip-top {
    left: 50%;
    -webkit-transform: translate(-50%, 0);
        -ms-transform: translate(-50%, 0);
            transform: translate(-50%, 0);
}
/** Common styles: Bottom positions **/
.tooltip, /*** Default is equivalent to .tip-bottom ***/
.tooltip.tip-bottom,
.tooltip.tip-bottom-left,
.tooltip.tip-bottom-right {
    top: 110%;
    top: calc(100% + 5px);
}
/** Common styles: Top positions **/
.tooltip.tip-top,
.tooltip.tip-top-left,
.tooltip.tip-top-right {
    top: auto;
    bottom: 110%;
    bottom: calc(100% + 5px);
}
/** Common styles: Corner positions **/
.tooltip.tip-bottom-left,
.tooltip.tip-bottom-right,
.tooltip.tip-top-left,
.tooltip.tip-top-right {
    -webkit-transform: none;
        -ms-transform: none;
            transform: none;
}
/** Common styles: Left corner positions **/
.tooltip.tip-bottom-left,
.tooltip.tip-top-left {
    right: 50%;
    left: auto;
    margin-right: -25px;
}
/** Common styles: Right corner positions **/
.tooltip.tip-bottom-right,
.tooltip.tip-top-right {
    margin-left: -25px;
}
/** Common styles: Vertically Centered **/
.tooltip.tip-left,
.tooltip.tip-right {
    top: 50%;
    -webkit-transform: translate(0, -50%);
        -ms-transform: translate(0, -50%);
            transform: translate(0, -50%);
}
/** Left position only **/
.tooltip.tip-left {
    right: 110%;
    right: calc(100% + 5px);
    left: auto;
}
/** Right position only **/
.tooltip.tip-right {
    left: 110%;
    left: calc(100% + 5px);
}

/* Tooltip arrow shared base styles */
.tooltip:after {
    content: ' ';
    display: block;
    position: absolute;
    width: 0;
    height: 0;
    border-width: 10px;
    border-style: solid;
    pointer-events: none;
}
/** Common styles: Horizontally Centered, Up/Down arrows **/
.tooltip:after, /*** Default is equivalent to .tip-bottom:after; ***/
.tooltip.tip-bottom:after,
.tooltip.tip-top:after {
    left: 50%;
    margin-left: -10px;
}
/** Common styles: Up arrow **/
.tooltip:after, /*** Default is equivalent to .tip-bottom:after; ***/
.tooltip.tip-bottom:after,
.tooltip.tip-bottom-left:after,
.tooltip.tip-bottom-right:after {
    top: -20px;
    border-color: transparent transparent #373739 transparent;
}
/** Common styles: Down arrow **/
.tooltip.tip-top:after,
.tooltip.tip-top-left:after,
.tooltip.tip-top-right:after{
    top: auto;
    bottom: -20px;
    border-color: #373739 transparent transparent transparent;
}
/** Common styles: Left-/Right-aligned, Up/Down arrows **/
.tooltip.tip-bottom-left:after,
.tooltip.tip-bottom-right:after,
.tooltip.tip-top-left:after,
.tooltip.tip-top-right:after {
    margin-left: 0;
}
/** Common styles: Right-aligned, Up/Down arrows **/
.tooltip.tip-bottom-left:after,
.tooltip.tip-top-left:after {
    right: 15px;
    left: auto;
}
/** Common styles: Left-aligned, Up/Down arrows **/
.tooltip.tip-bottom-right:after,
.tooltip.tip-top-right:after {
    left: 15px;
}
/** Common styles: Vertically Centered, Left/Right arrows **/
.tooltip.tip-left:after,
.tooltip.tip-right:after {
    top: 50%;
    margin-top: -10px;
    margin-left: auto;
}
/** Right arrow **/
.tooltip.tip-left:after {
    right: -20px;
    left: auto;
    border-color: transparent transparent transparent #373739;
}
/** Left arrow **/
.tooltip.tip-right:after {
    left: -20px;
    border-color: transparent #373739 transparent transparent;
}
              
            
!

JS

              
                // Fully accessible tooltip jQuery plugin with delegation.
// Ideal for view containers that may re-render content.
(function ($) {
  $.fn.tooltip = function () {
    this

    // Delegate to tooltip, Hide if tooltip receives mouse or is clicked (tooltip may stick if parent has focus)
      .on('mouseenter click', '.tooltip', function (e) {
        e.stopPropagation();
        $(this).removeClass('isVisible');
      })
      // Delegate to parent of tooltip, Show tooltip if parent receives mouse or focus
      .on('mouseenter focus', ':has(>.tooltip)', function (e) {
        if (!$(this).prop('disabled')) { // IE 8 fix to prevent tooltip on `disabled` elements
          $(this)
            .find('.tooltip')
            .addClass('isVisible');
        }
      })
      // Delegate to parent of tooltip, Hide tooltip if parent loses mouse or focus
      .on('mouseleave blur keydown', ':has(>.tooltip)', function (e) {
        if (e.type === 'keydown') {
          if(e.which === 27) {
            $(this)
              .find('.tooltip')
              .removeClass('isVisible');
          }
        } else {
          $(this)
            .find('.tooltip')
            .removeClass('isVisible');
        }
      });
    return this;
  };
}(jQuery));

// Bind event listener to container element
$('.namespace').tooltip();
              
            
!
999px

Console