Modern CSS Tooltips And Speech Bubbles (Part 1)<\/h1>\nTemani Afif<\/address>\n 2024-03-01T12:00:00+00:00
\n 2024-06-12T20:05:40+00:00
\n <\/header>\n
In a previous article<\/a>, we explored ribbon shapes and different ways to approach them using clever combinations of CSS gradients and clip-path()<\/code>. This time, I\u2019d like to explore another shape, one that you\u2019ve likely had to tackle at least once in your front-end life: tooltips<\/strong>. You know what we\u2019re talking about, those little things that look like speech bubbles from comic books. They\u2019re everywhere in the wild, from a hover effect for buttons<\/a> to the text messaging app on your phone<\/a>.<\/p>\nThe shapes may look easy to make in CSS at first glance, but it always ends with a lot of struggles. For example, how do you adjust the position of the tail to indicate whether the tooltip is coming from a left, right, or center position? There are plenty of considerations to take into account<\/a> when making tooltips \u2014 including overflowage<\/a>, collision detection<\/a>, and semantics<\/a> \u2014 but it\u2019s the shape and direction of the tail that I want to focus on because I often see inflexible fixed units used to position them.<\/p>\nForget what you already know about tooltips because in this article, we will start from zero, and you will learn how to build a tooltip with minimal markup powered by modern CSS that provides flexibility to configure the component by adjusting CSS variables. We are not going to build one or two shapes, but\u2026 100 different shapes!<\/em><\/p>\nThat may sound like we\u2019re getting into a super-long article, but actually, we can easily get there by adjusting a few values. In the end, you will have a back pocket full of CSS tricks that can be combined to create any shape you want.<\/p>\n
\n 2024-06-12T20:05:40+00:00
\n <\/header>\n
clip-path()<\/code>. This time, I\u2019d like to explore another shape, one that you\u2019ve likely had to tackle at least once in your front-end life: tooltips<\/strong>. You know what we\u2019re talking about, those little things that look like speech bubbles from comic books. They\u2019re everywhere in the wild, from a hover effect for buttons<\/a> to the text messaging app on your phone<\/a>.<\/p>\nThe shapes may look easy to make in CSS at first glance, but it always ends with a lot of struggles. For example, how do you adjust the position of the tail to indicate whether the tooltip is coming from a left, right, or center position? There are plenty of considerations to take into account<\/a> when making tooltips \u2014 including overflowage<\/a>, collision detection<\/a>, and semantics<\/a> \u2014 but it\u2019s the shape and direction of the tail that I want to focus on because I often see inflexible fixed units used to position them.<\/p>\nForget what you already know about tooltips because in this article, we will start from zero, and you will learn how to build a tooltip with minimal markup powered by modern CSS that provides flexibility to configure the component by adjusting CSS variables. We are not going to build one or two shapes, but\u2026 100 different shapes!<\/em><\/p>\nThat may sound like we\u2019re getting into a super-long article, but actually, we can easily get there by adjusting a few values. In the end, you will have a back pocket full of CSS tricks that can be combined to create any shape you want.<\/p>\n