點燈坊

失くすものさえない今が強くなるチャンスよ

Using hover to Style the Hovered Element

Sam Xiao's Avatar 2022-01-25

We can use hover modifier to style the element when hovered.

Version

TailwindCSS 3.0

hover

hover000

The hyperlink is red when hovered.

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
  <title>TailwindCSS</title>
</head>
<body>
  <a class="hover:text-red-500" href="#">My Blog</a>
</body>

Line 10

<a class="hover:text-red-500" href="#">My Blog</a>
  • hover : style the element when hovered

Conclusion

  • hover modifier is not only used on <a>, but also other element

Reference

TailwindCSS, hover