pure-css/pure

Styling file upload button

jcbsv opened this issue · 0 comments

jcbsv commented

I suggest to revive issue #812 regarding styling of upload buttons.

The ::file-selector-button CSS selector now has wide (if not universal) adoption.

The following code (adopted from buttons-core.css and buttons.css) shows an example implementation:

input::file-selector-button {
    display: inline-block;
    line-height: normal;
    white-space: nowrap;
    vertical-align: middle;
    text-align: center;
    cursor: pointer;
    -webkit-user-drag: none;
    user-select: none;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 100%;
    padding: 0.5em 1em;
    color: rgba(0, 0, 0, 0.80);
    border: none rgba(0, 0, 0, 0);
    background-color: #E6E6E6;
    text-decoration: none;
    border-radius: 2px;
}

input::file-selector-button:hover,
input::file-selector-button:focus {
    background-image: linear-gradient(transparent, rgba(0,0,0, 0.05) 40%, rgba(0,0,0, 0.10));
}
input::file-selector-button:focus {
    outline: 0;
}
input::file-selector-button:active {
    box-shadow: 0 0 0 1px rgba(0,0,0, 0.15) inset, 0 0 6px rgba(0,0,0, 0.20) inset;
    border-color: #000;
}

The result in Safari (Swedish language):
Skärmavbild 2023-11-23 kl  07 52 07