點燈坊

うまく使いさえすれば、時間はいつも十分にある

Using visited to Style the Visited Element

Sam Xiao's Avatar 2022-01-25

We can use visited modifier to style the element when visited.

Version

TailwindCSS 3.0

visited

visited000

The hyperlink is red when visited.

<!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="text-blue-600 visited:text-red-500" href="#">My Blog</a>
</body>

Line 10

<a class="text-blue-600 visited:text-red-500" href="#">My Blog</a>
  • text-blue-600 : style default color for the element
  • visited:text-red-500 : style the visited element

If only setting the visited is invalid, you must also set default color for the element

Conclusion

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

Reference

TailwindCSS, visited