::file-selector-button
Baseline
åºãå©ç¨å¯è½
ãã®æ©è½ã¯åºãå®è£ ããã¦ãããå¤ãã®ãã¼ã¸ã§ã³ã®ç«¯æ«ããã©ã¦ã¶ã¼ã§åä½ãã¾ãã2021å¹´4æä»¥éããã¹ã¦ã®ãã©ã¦ã¶ã¼ã§å©ç¨å¯è½ã§ãã
::file-selector-button 㯠CSS ã®æ¬ä¼¼è¦ç´ ã§ã<input> è¦ç´ ã® type="file" ã®ãã¿ã³ã表ãã¾ãã
試ãã¦ã¿ã¾ããã
input {
margin-top: 1rem;
}
input::file-selector-button {
font-weight: bold;
color: dodgerblue;
padding: 0.5em;
border: thin solid grey;
border-radius: 3px;
}
<label for="avatar">ãããã£ã¼ã«ç»åã鏿:</label><br />
<input id="avatar" type="file" name="avatar" accept="image/png, image/jpeg" />
æ§æ
css
::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;
}
ä¾
仿§æ¸
| 仿§æ¸ |
|---|
| CSS Pseudo-Elements Module Level 4 > # file-selector-button-pseudo > |