LoginSignup
4
5

More than 5 years have passed since last update.

:placeholder-shown疑似クラス

Last updated at Posted at 2018-10-11

:placeholder-shown

プレースホルダーが表示されている要素 という擬似クラスです
input や textarea を指します
何か入力してプレースホルダーが表示されなくなるとスタイルが当たらなくなります

IE,edgeでは利用不可

<input placeholder="名前を入力" class="name">

.name:placeholder-shown {
  opacity: 1;
  color: #ff0000;
  background: #f0f0f0;
  font-weight: bold;
  border: 2px solid red;
}

::placeholder

プレースホルダーのテキストの疑似要素です。
::before や ::after の疑似要素はコロンが1つでもいいのですがこれは2つ必要。

<input placeholder="住所を入力" class="address">

.address::placeholder {
  opacity: 1;
  color: #ff0000;
  background: #f0f0f0;
  font-weight: bold;
  border: 2px solid red;
}

:not()とtransform を利用することで下記のような動きのある入力フォームも作成できます。

4
5
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
4
5