LoginSignup
0
0

More than 3 years have passed since last update.

リンクを押したときに青から紫ではなく、別の色に変える方法

Last updated at Posted at 2020-10-20

はじめに

結論:疑似クラスで解決できる

疑似クラスとは

疑似クラスとは、指定の要素が特定の状態である場合にスタイルを適用させるセレクタ。
【初心者向け】CSSの擬似要素と擬似クラスを理解しよう!

解決方法

リンクの状態によって解決方法は2種類。

  • 既にリンク先に訪問したことがある状態 ⇒ :visited疑似クラス
  • リンク上にフォーカスがある状態    ⇒ :focus疑似クラス
既にリンク先に訪問したことがある状態
a:visited {
  color: red;
}

リンク上にフォーカスがある状態
a:focus {
   color: yellow;
}

※「visited」⇒「focus」の順番で指定しないと、「focus」が効きません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0