DEV Community

Cover image for Incredibly simple Talk Bubbles with Tailwind
pierdomenico reitano
pierdomenico reitano

Posted on

18 1 1 2 1

Incredibly simple Talk Bubbles with Tailwind

Tailwind is a utility-first css framework that gives us the opportunity to develop the style of our projects quickly and, at the same time, compared to other frameworks, it saves precious bytes because it removes unused CSS during the production build.

I'm going to show you how easy it is to create a talk bubble using a couple of cool tricks.

For the first step we will create a flex container that hold and position contained items.

<!-- Left aligned bubble -->
<div class="flex items-center justify-start">
</div>
<!-- Right aligned bubble -->
<div class="flex items-center justify-end">
</div>
Enter fullscreen mode Exit fullscreen mode

Next we need to create the arrow, using transform-origin and rotate utilities we will change the set the direction.

<div class="w-3 overflow-hidden">
  <!-- Left aligned bubble -->
  <div 
  class="h-4 bg-green-400 transform rotate-45 origin-bottom-right rounded-sm">
  </div>
  <!-- Right aligned bubble -->
  <div 
  class="h-4 bg-green-400 transform rotate-45 origin-top-left rounded-sm">
  </div>
</div>
Enter fullscreen mode Exit fullscreen mode

Note, giving fixed width to container and fixed height to arrow item is needed if we want to reproduce the effect of the talking bubble.

Final Result

If you're seeking inspiration, I recommend visiting the showcase section of the official Tailwind website. You can find it at https://tailwindcss.com/showcase. This section displays numerous remarkable projects that have been created using the exceptionally user-friendly Tailwind framework.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more