::file-selector-button

::file-selector-buttonCSS擬似要素で、<input> 要素の type="file" のボタンを表します。

試してみましょう

構文

css
selector::file-selector-button

基本的な例

HTML

html
<form>
  <label for="fileUpload">ファイルをアップロードしてください</label>
  <input type="file" id="fileUpload" />
</form>

CSS

css
input[type="file"]::file-selector-button {
  border: 2px solid #6c5ce7;
  padding: 0.2em 0.4em;
  border-radius: 0.2em;
  background-color: #a29bfe;
  transition: 1s;
}

input[type="file"]::file-selector-button:hover {
  background-color: #81ecec;
  border: 2px solid #00cec9;
}

結果

::file-selector-button は要素全体であり、UA スタイルシートのルールと一致することを覚えておいてください。 特に、フォントや色は必ずしも input 要素から継承されるとは限りません。

代替の例

HTML

html
<form>
  <label for="fileUpload">ファイルをアップロードしてください</label>
  <input type="file" id="fileUpload" />
</form>

CSS

css
input[type="file"]::file-selector-button {
  border: 2px solid #6c5ce7;
  padding: 0.2em 0.4em;
  border-radius: 0.2em;
  background-color: #a29bfe;
  transition: 1s;
}

input[type="file"]::-ms-browse:hover {
  background-color: #81ecec;
  border: 2px solid #00cec9;
}

input[type="file"]::-webkit-file-upload-button:hover {
  background-color: #81ecec;
  border: 2px solid #00cec9;
}

input[type="file"]::file-selector-button:hover {
  background-color: #81ecec;
  border: 2px solid #00cec9;
}

仕様書

Specification
CSS Pseudo-Elements Module Level 4
# file-selector-button-pseudo

ブラウザーの互換性

BCD tables only load in the browser

関連情報