Есть довольно много методов для <input type="file" />
элемента. Я попробовал большинство из них, но ни один не был достаточно хорош. Вероятно, худшей техникой была та, в которой входной элемент помещается в емкость (которая имитирует кнопки), а на вход следует за курсором, так что, когда вы щелкните в любом месте на контейнере, вы нажимаете на ввод. Звучит интересно и странно одновременно, верно? Во всяком случае, он имел некоторые неприемлемые недостатки (удобство использования, сенсорный).
Вот и я использовал данный скрипт в форме отправки отзыва на странице www.s-sd.ru/otzyvy/
jquery
Ну вы наверное знаете, что ставим их между тегами <head>...</head>
.
<script src="js/custom-file-input.js"></script>
<script src="js/jquery-v1.min.js"></script>
<script src="js/jquery.custom-file-input.js"></script>
HTML
<div class="box">
<input type="file" name="file-1[]" id="file-1" class="inputfile inputfile-1" data-multiple-caption="{count} files selected" multiple />
<label for="file-1"><!-- Иконка --><span>Загрузить файл…</span></label>
</div>
JS
Ставите в удобное для вас место, можно рядом с новой формой <input type="file" />
(function(e,t,n){var r=e.querySelectorAll("html")[0];r.className=r.className.replace(/(^|\s)no-js(\s|$)/,"$1js$2")})(document,window,0);
CSS
Стили очень просты и не обязательно подключать весь component.css
, а выбрать нолько нужную вам кнопку. Вод стиль для первой кнопки:
.js .inputfile {
width: 0.1px;
height: 0.1px;
opacity: 0;
overflow: hidden;
position: absolute;
z-index: -1;
}
.inputfile + label {
max-width: 80%;
font-size: 1.25rem;
/* 20px */
font-weight: 700;
text-overflow: ellipsis;
white-space: nowrap;
cursor: pointer;
display: inline-block;
overflow: hidden;
padding: 0.625rem 1.25rem;
/* 10px 20px */
}
.no-js .inputfile + label {
display: none;
}
.inputfile:focus + label,
.inputfile.has-focus + label {
outline: 1px dotted #000;
outline: -webkit-focus-ring-color auto 5px;
}
.inputfile + label * {
/* pointer-events: none; */
/* in case of FastClick lib use */
}
.inputfile + label svg {
width: 1em;
height: 1em;
vertical-align: middle;
fill: currentColor;
margin-top: -0.25em;
/* 4px */
margin-right: 0.25em;
/* 4px */
}
/* style 1 */
.inputfile-1 + label {
color: #f1e5e6;
background-color: #d3394c;
}
.inputfile-1:focus + label,
.inputfile-1.has-focus + label,
.inputfile-1 + label:hover {
background-color: #722040;
}
@media screen and (max-width: 50em) {
.inputfile-6 + label strong {
display: block;
}
}
Результат
Вот и всё
Материал взят из зарубежного источника и представлен исключительно в ознакомительных целях.