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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <h2>Bulletproof Pure CSS Tooltips</h2>

<main>
  <p>Use the range slider below to adjust the body font size. The tooltip uses em units (which are based on the pixels of the parent font size), so the size, padding, and position of the tooltip stays relative to the link.<p>
  
  <p class="tt">Lorem ipsum dolor sit amet <a href="#" data-tooltip="This is a pure CSS tooltip">hover over this link</a> elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam, <a href="#" data-tooltip="This is a pure CSS tooltip">hover over this link which is longer than the other</a> quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
  
  <p>You'll also notice at certain sizes the link spans two lines and the tooltip still appears at a comfortable location.</p>

  <p class="range"><input type="range" min="10" max="30" step="1" value="20" id="slider"></p>
</main>
              
            
!

CSS

              
                body {
  font-size: 24px;
  line-height: 1.4;
  padding: 0 20px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

h2 {
  text-align: center;
  font-size: 30px;
}

main {
  margin: 0 auto;
  max-width: 650px;
}

.tt {
  color: firebrick;
}

.range {
  text-align: center;
  font-size: 20px;
  position: absolute;
  bottom: 0;
  left: 30px;
  right: 30px;
}

a[data-tooltip]:link, a[data-tooltip]:visited {
  position: relative;
  text-decoration: none;
	border-bottom: solid 1px;
}

a[data-tooltip]:before {
	content: "";
	position: absolute;
	border-top: 1em solid #0090ff;
	border-left: 1.5em solid transparent;
	border-right: 1.5em solid transparent;
	display: none;
  top: -1em;
}

a[data-tooltip]:after {
	content: attr(data-tooltip);
	position: absolute;
	color: white;
	top: -2.5em;
  left: -1em;
	background: #0090ff;
	padding: .25em .75em;
	border-radius: .5em;
	white-space: nowrap;
	display: none;
}

a[data-tooltip]:hover:before, a[data-tooltip]:hover:after {
	display: inline;
}

/* credit: https://css-tricks.com/styling-cross-browser-compatible-range-inputs-css/ */
input[type=range] {
  -webkit-appearance: none;
  width: 100%;
}

input[type=range]:focus {
  outline: none;
}

input[type=range]::-webkit-slider-runnable-track {
  width: 100%;
  height: 8.4px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
  background: #0090ff;
  border-radius: 1.3px;
  border: 0.2px solid #010101;
}

input[type=range]::-webkit-slider-thumb {
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
  border: 1px solid #000000;
  height: 36px;
  width: 16px;
  border-radius: 3px;
  background: #ffffff;
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -14px;
}

input[type=range]:focus::-webkit-slider-runnable-track {
  background: #0090ff;
}

input[type=range]::-moz-range-track {
  width: 100%;
  height: 8.4px;
  cursor: pointer;
  animate: 0.2s;
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
  background: #3071a9;
  border-radius: 1.3px;
  border: 0.2px solid #010101;
}

input[type=range]::-moz-range-thumb {
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
  border: 1px solid #000000;
  height: 36px;
  width: 16px;
  border-radius: 3px;
  background: #ffffff;
  cursor: pointer;
}

input[type=range]::-ms-track {
  width: 100%;
  height: 8.4px;
  cursor: pointer;
  animate: 0.2s;
  background: transparent;
  border-color: transparent;
  border-width: 16px 0;
  color: transparent;
}

input[type=range]::-ms-fill-lower {
  background: #2a6495;
  border: 0.2px solid #010101;
  border-radius: 2.6px;
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}

input[type=range]::-ms-fill-upper {
  background: #3071a9;
  border: 0.2px solid #010101;
  border-radius: 2.6px;
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
}

input[type=range]::-ms-thumb {
  box-shadow: 1px 1px 1px #000000, 0px 0px 1px #0d0d0d;
  border: 1px solid #000000;
  height: 36px;
  width: 16px;
  border-radius: 3px;
  background: #ffffff;
  cursor: pointer;
}

input[type=range]:focus::-ms-fill-lower {
  background: #3071a9;
}

input[type=range]:focus::-ms-fill-upper {
  background: #367ebd;
}
              
            
!

JS

              
                let slider = document.getElementById('slider'),
    b = document.body;

slider.oninput = function () {
  b.style.fontSize = this.value + 'px';
  op.innerHTML = this.value + 'px';
}
              
            
!
999px

Console