Skill ID: Interactive_36
Description: Make a button change color, a link get an underline, etc., on hover.
Where to apply: Buttons, links, navigation items, interactive cards.
Key Tailwind Classes:
hover:bg-blue-700
,
hover:underline
Gotcha:
Not adding a
transition
class will make hover effects instant and potentially jarring. A smooth
transition-colors duration-150
makes it feel much more polished. Overdoing hover effects can also be distracting.
Hover over the button and the link below to see the effects:
<button class="bg-blue-500 text-white font-semibold py-2 px-4 rounded-md
hover:bg-blue-700
transition-colors duration-150">
Hover Me
</button>
<a href="#" class="text-indigo-600
hover:underline hover:text-indigo-800
transition-colors duration-150">
Hoverable Link
</a>
In this example:
bg-blue-500
to
bg-blue-700
on hover, specified by
hover:bg-blue-700
.
text-indigo-600
to
text-indigo-800
on hover, specified by
hover:underline
and
hover:text-indigo-800
.
transition-colors duration-150
for a smooth visual transition, as highlighted in the "Gotcha" section.