DEV Community

Cover image for CSS Only Tooltips

CSS Only Tooltips

Chris Bongers on August 07, 2020

Today we will be building some tooltips with nothing more than CSS. The idea is we hide the tooltip, and we will show it once hovering over the div...
Collapse
 
kallmanation profile image
Nathan Kallman

This can be done without the fixed width and without the extra markup and classes:

Collapse
 
link2twenty profile image
Andrew Bone
Collapse
 
dailydevtips1 profile image
Chris Bongers

Very nice, I love how many ways there are to solve one problem.
Definitely going to give the attributes a try

Collapse
 
dailydevtips1 profile image
Chris Bongers

Hey, That's a very neat solution man!
How is the browser support on those selectors?

I do guess my solution could be converted to use the dynamic width, but I like your approach!

Collapse
 
kallmanation profile image
Nathan Kallman

I haven't tested extensively... but caniuse gives pretty wide support:
caniuse.com/#feat=css-gencontent
caniuse.com/#search=attribute%20se...
caniuse.com/#feat=calc

The most problematic one looking to be calc in IE may or may not work correctly

Thread Thread
 
dailydevtips1 profile image
Chris Bongers

Nice, I'm going to give them a try

Thread Thread
 
dailydevtips1 profile image
Chris Bongers

Awesome, these selectors are amazing, created the alternative way as well:

dev.to/dailydevtips1/css-only-tool...

Collapse
 
dailydevtips1 profile image
Chris Bongers

It is embedded above, but dev.to doesn't seem to render the codepens. So someone asked me if i could at-least add images so they could see how it looks.

Collapse
 
link2twenty profile image
Andrew Bone • Edited

You can input a line like this in you markdown

{% codepen https://codepen.io/rebelchris/pen/LYNEYEv %}

and it will render like this in your post

There's plenty of good stuff in the editor guide

Thread Thread
 
dailydevtips1 profile image
Chris Bongers

Awesome man, It seems to work different on all platforms haha, probably should have read the editor guide yes 🤯