6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

セレクトボックスのCSS適用が意外に難しい

Last updated at Posted at 2019-10-25

shadowが消えない

Screen Shot 2019-10-25 at 13.07.47.png

↓ クリックすると shadow がつく

Screen Shot 2019-10-25 at 13.07.52.png

やりがちなCSS

common.scss
.select:focus {
  box-shadow: none;
}

input の場合だとこれで消えるが、 select の場合はこれじゃ消えない

実はこうです

common.scss
.select:focus {
  outline: none;
}

2020/01/31追記

button タグも select と同様のやり方で消えます。

border-radius が消えない(矢印も消えない)

矢印は↓ココのこと
Screen Shot 2019-10-25 at 13.15.17.png

やりがちなCSS

common.scss
.select {
  border-radius: 0;
}

input の場合だとこれで十分だけど、なぜか select の場合はこれじゃ消えない

実はこうです

common.scss
.select {
  -webkit-appearance: none; //追加
  -moz-appearance: none;  //追加
  appearance: none; //追加
  border-radius: 0;
}

上記三行を追加して、セレクトボックスのそもそものデザインを初期化する必要があるらしい。
(appearance:プラットフォームにおける標準的なUIの外観にする)

参考

http://www.htmq.com/css3/appearance.shtml
https://hacknote.jp/archives/9505/
http://nakagaw.hateblo.jp/entry/2015/06/18/164021

6
9
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
6
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?