0
0

More than 1 year has passed since last update.

Safariではoption要素をhiddenできない

Posted at

問題

optionにhiddenをつけた場合、Chromeでは期待通りに動きますが、Safari(やiPhoneのwebview)では選択肢としてでてきてしまいます。。

<select name="choice">
  <option hidden>choose...</option>
  <option>First</option>
  <option>Second</option>
  <option>Third</option>
</select>

Sampleコード

Chrome Safari
image.png image.png

原因

Safariのバグのようでhiddenやdisplay:noneが効かないようでした。
https://bugs.webkit.org/show_bug.cgi?id=8351
https://stackoverflow.com/questions/9234830/how-to-hide-a-option-in-a-select-menu-with-css

対策

hiddenではなくdisabledのほうを使いましょう
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option

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