Tuỳ chỉnh nút tập tin tải lên sử dụng html css và js
Html mã:
<div class="custom-file-upload">
<!--<label for="file">File: </label>-->
<input type="file" id="file" name="myfiles[]" multiple />
</div>
CSS:
.custom-file-upload-hidden {
display: none;
visibility: hidden;
position: absolute;
left: -9999px;
}
.custom-file-upload {
display: block;
width: auto;
font-size: 16px;
margin-top: 30px;
}
.custom-file-upload label {
display: block;
margin-bottom: 5px;
}
.file-upload-wrapper {
position: relative;
margin-bottom: 5px;
}
.file-upload-input {
width: 300px;
color: #fff;
font-size: 16px;
padding: 11px 17px;
border: none;
background-color: #c0392b;
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
float: left;
/* IE 9 Fix */
}
.file-upload-input:hover, .file-upload-input:focus {
background-color: #ab3326;
outline: none;
}
.file-upload-button {
cursor: pointer;
display: inline-block;
color: #fff;
font-size: 16px;
text-transform: uppercase;
padding: 11px 20px;
border: none;
margin-left: -1px;
background-color: #962d22;
float: left;
/* IE 9 Fix */
-moz-transition: all 0.2s ease-in;
-o-transition: all 0.2s ease-in;
-webkit-transition: all 0.2s ease-in;
transition: all 0.2s ease-in;
}
.file-upload-button:hover {
background-color: #6d2018;
}
JS Mã sản phẩm: http://codepen.io/wallaceerick/pen/fEdrz kiểm tra này để biết chi tiết hoàn chỉnh
Một người sử dụng muốn chỉnh sửa trên với nhận xét này. Thêm vào đây: Đáng buồn thay, những gì bạn phải làm để kiểu đầu vào kiểu = "tập tin" tại thời điểm này. CSS và JavaScript bạn chọn để tạo kiểu cho nó hoàn toàn tùy thuộc vào bạn. Tôi tìm thấy jsfiddle này được tạo bởi [gabrieleromanato] (http://gabrieleromanato.com/) để hiển thị cho bạn một tùy chọn CSS khác để tạo kiểu. – Yakk
Xem thêm: [Kiểu tệp kiểu đầu vào? duplicate] (http://stackoverflow.com/questions/4909228/style-input-type-file) [Làm cách nào để tạo kiểu "tệp đầu vào" bằng CSS3/Javascript?] (http://stackoverflow.com/questions/3226167/ how-to-style-input-file-với-css3-javascript) [Tạo kiểu đầu vào = nút "tệp".] (http://stackoverflow.com/questions/572768/styling-an-input-type-file -button) – Yakk