2020-06-29
1153
#css
Supun Kavinda
21189
Jun 29, 2020 â‹… 4 min read

Creating beautiful tooltips with only CSS

Supun Kavinda I started as a self-taught PHP developer before creating my own company, Hyvor. I am particularly interested in physics and machine learning.

Recent posts:

Building a Full-Featured Laravel Admin Dashboard with Filament

Building a full-featured Laravel admin dashboard with Filament

Build scalable admin dashboards with Filament and Laravel using Form Builder, Notifications, and Actions for clean, interactive panels.

Kayode Adeniyi
Dec 20, 2024 â‹… 5 min read
Working With URLs In JavaScript

Working with URLs in JavaScript

Break down the parts of a URL and explore APIs for working with them in JavaScript, parsing them, building query strings, checking their validity, etc.

Joe Attardi
Dec 19, 2024 â‹… 6 min read
Lazy Loading Vs. Eager Loading

Lazy loading vs. Eager loading

In this guide, explore lazy loading and error loading as two techniques for fetching data in React apps.

Njong Emy
Dec 18, 2024 â‹… 5 min read
Deno logo over an orange background

How to migrate your Node.js app to Deno 2.0

Deno is a popular JavaScript runtime, and it recently launched version 2.0 with several new features, bug fixes, and improvements […]

Yashodhan Joshi
Dec 17, 2024 â‹… 7 min read
View all posts

16 Replies to "Creating beautiful tooltips with only CSS"

  1. There is a big issue with this tooltip.
    Actually, setting its opacity to 0 makes it disappear to the users eyes only, to to their mouse pointer.
    So, the tooltip actually shows up even though we don’t hover the triggering element, but also where the tooltip is supposed to be…

  2. I noticed this too, but I found an easy fix! Just add “visibility: hidden;” wherever it says “opacity:0;”, and add “visibility: visible;” wherever it says “opacity:1;”. Should work like a charm.

    1. This does work, but I found that it undoes the transition when you hover off the tooltip (in the case that it contains a link). So, the opacity changes over the specified time when you hover the triggering element, but “snaps” off when you unhover over it or the tooltip itself.

  3. Is there a way to do this with a list of generated items in the tooltip? I tried doing this, but the list has a bunch of text in it instead of actual line breaks. In other words, can it only be text when you use this method to make the tooltip?

  4. For reasons I haven’t figured out, if there are two items with tooltips, one immediately below the other, you can “see through” the upper one to the content of the one below it. With white text, this shows up as imperfections in the letters. The effect is much more apparent with black text on a buff yellow background. The fix is to give the tooltip class a z-index larger than anything else in the area right after “position: absolute;”

  5. I’ve also added “transition-delay: 100ms;” right after transition. I have three tooltips one below the other, and this keeps them from popping in and out if the skims over that area. An intentional hover is needed to make the tooltip disappear.

    With the small changes mentioned in the comments, I now have beautiful tooltips. Thank you,
    Supun Kavinda!

  6. This is terrific! I saw you wrote that “You can use the same method to create classes for bottom and top positions. Additionally, you’ll need to reset the top value and override the transform value accordingly,” though, and I’ve been playing with the CSS for quite awhile, but can’t fully figure out how to reset and override the CSS correctly to get top and bottom tooltips working–could you (or anyone else seeing this) let me know how I can do this? Any help would be greatly appreciated!

  7. Hi All,

    I have managed to get the box to appear at the top, however when I apply this effect to the next word in my paragraph which I also want the hover to appear, the second tooltip starts out hovering where the first tooltip was and then when it fades out, it jumps to the second word.

    How would I position the second tooltip to appear above the second word initially instead of inheriting the first tooltip position?

    Would really appreciate some feedback here.

    Thanks,

    Simon Carter

Leave a Reply