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

              
                <body>
  <div id="mainContainer">
    <div id="explanation">Not entirely happy with the solution. Would have preffered to avoid using time-outs, but in the end the visual effect is kind of neat.</div>
    <div class="centered">
      <button id="target" title="Well isn't this exciting." class="aDiv">Hover here</button>
    </div>
  </div>
</body>
              
            
!

CSS

              
                button:hover{
  background: blue;
}

#explanation{
  margin:auto;
  width:500px;;
}

.aDiv{
  position:relative;
  display:block;
  margin:auto;
  width:200px;
  height:100px;
  border-radius:30px;
  border:1px solid blue;
  color:#96b38a;  
  background: #1d1f20;
  margin-bottom:5px;
  margin-top:5px;
}

.aTooltip{
  border:5px solid red;
}

.centered{
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 50%;
    max-height: 50%;
    margin: auto;
}

.mainContainer{
  height:100%;
  width:100%;
  position:relative;
}

body{
  height:100%;  
}

html {
  height: 100%;
  color:#96b38a;  
  background: #1d1f20;
}
              
            
!

JS

              
                // "When all else fails, build your own tooltip, with blackjack and hookers." 
// - Benjamin Franklin

// https://api.jqueryui.com/tooltip/

/*
Hijacks the usual jQuery Tooltip Widget functionality, in order to allow the user to copy-paste the text in the tooltip.
Usually, the tooltip dissapears when the user tries to hover on it. We override that behavior and introduce two rules for closing the tooltip: when the cursor leaves the tooltip, or 300ms after the cursor leaves the target element (if the cursor is not on the tooltip at that point).
*/
  console.log("We're online.");
  var cursorOnTooltip = false;

  $("#target").on("mouseleave", function(ev){
    ev.stopImmediatePropagation(); //don't allow the Tooltip Widget to get hold of this event
    
    window.setTimeout(function(){
      if (!cursorOnTooltip)
        {
          $('#target').tooltip("close");
        }
    }, 300); //close the tooltip when the cursor leaves our element, if the cursor is not on the tooltip
    
    $(".aTooltip").on("mouseenter", function(ev){
      cursorOnTooltip = true; //mark the flag so that the tooltip doesn't get closed after 300ms
    });
    $(".aTooltip").on("mouseleave", function(ev){
      // if the cursor leaves the tooltip, close it and unbind all handlers
      cursorOnTooltip = false;
      $('#target').tooltip("close");
      $(this).unbind("mouseleave");
      $(this).unbind("mouseenter");
    });
  });

  $('#target').tooltip({
  		tooltipClass: "aTooltip",
      position: {
  			my: "left bottom",
  			at: "left top"
  		},
  		track:false
  	});	
              
            
!
999px

Console