自定义上传按钮

| 嗨,我只是想知道如何创建自己的自定义文件上传按钮,因为我能做的最好的就是 而我想要实现的是 无论如何,我将非常感激, 请问我有答案来解释如何使用代码,而不是网站链接的答案,允许您下载按钮或类似的东西,谢谢:)     
已邀请:
        尽管这些答案中的一些会创建出看起来像您希望它起作用的东西,但是当它们尝试以您期望的方式执行时,它们将分解。文件输入的样式不正确,您将难以尝试。但是,有一个窍门。 诀窍是将输入的不透明度设为0,然后将其下方的背景更改为所需的按钮样式。
.file_button_container,
.file_button_container input {
     height: 47px;
     width: 263px;
 }

 .file_button_container {
     background: transparent url(http://i.stack.imgur.com/BT5AB.png) left top no-repeat;
 }

 .file_button_container input {
     opacity: 0;
 }
<div class=\"file_button_container\"><input type=\"file\" /></div>
        我认为您也可以尝试这样做: 创建一个额外的
<label for=\"X\"></label>
元素,您可以使用CSS轻松设置样式
<div class=\"container\">
  <label for=\"upload\" class=\"uploadButton\">Upload</label>
  <input type=\"file\" name=\"upload\" id=\"upload\">
</div>
喜欢
.container {
  position: relative;
}
.uploadButton {
  height: 25px;
  width: 66px;
  display: block;
  cursor: pointer;
  background: url(\'http://www.ifunia.com/images/christmas/youtube-upload-button.gif\') center center no-repeat;
}
input[type=\"file\"] {
  display: block;
  width: 66px;
  height: 25px;
  clip: rect(0px 0px 0px 0px);
  position: absolute;
  left: 0;
  top: 0;
}
<form>
  <div class=\"container\">
    <label for=\"upload\" class=\"uploadButton\"></label>
    <input type=\"file\" name=\"upload\" id=\"upload\" required />
  </div>
  <hr/>
  <button type=\"submit\">Submit</button>
</form>
        使用CSS通过按钮的ID或类来设置按钮的样式。 这可能会有所帮助: http://speckyboy.com/2009/05/27/22-css-button-styling-tutorials-and-techniques/     
        箭头不是您可以“仅用代码完成的事情”,并且圆角在Firefox中可以正常工作,但在css中则无法使用...如果您只需要使用自定义图像,这很容易: CSS:
#my_upload_button{
  background-image:url(path-to-file.png);
  border:none;
}
    
        这是您要使用css / html的按钮的近似值 html
<button class=\"upload\">Choose a file to upload...</button>
的CSS
.upload{
    border:0;
    padding:10px 20px;
    -moz-border-radius:10px;
    border-radius:10px;
    background-color:#4488ee;
    color:white;
    font-size:16px;
}
演示http://jsfiddle.net/gaby/qdX5d/2/ 对于pre-IE9中的圆角,请使用css3pie     
        步骤1.创建一个简单的html标记
<div class=\"fileUpload btn btn-primary\">
    <span>Upload</span>
    <input type=\"file\" class=\"upload\" />
</div>
步骤2. CSS:棘手的部分
.fileUpload {
    position: relative;
    overflow: hidden;
    margin: 10px;
}
.fileUpload input.upload {
    position: absolute;
    top: 0;
    right: 0;
    margin: 0;
    padding: 0;
    font-size: 20px;
    cursor: pointer;
    opacity: 0;
    filter: alpha(opacity=0);
}
有关演示,请参见http://geniuscarrier.com/how-to-style-a-html-file-upload-button-in-pure-css/     
        使用输入的标签作为自定义上传按钮:
<label for=\"pic\" class=\"uploadfilelabel\" >upload </label>
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"110000\">
<input id=\"pic\" name=\"pic\" type=\"file\" size=\"110000\">
和CSS:
 label.uploadfilelabel{/*custom label here*/}
 input[type=file]{display:none;}
注意我们没有显示主输入按钮,因为否则它将占用空间     
        我来不及回答,但是将来肯定有人会发现它很有用,也不需要使用Javascript或Hidden字段。如果您使用的是Bootstrap,那么肯定也不需要btn CSS。
#upload_file 
{
    display: none;
}

.btn-primary {
    background-color: #007bff;
    border-color: #007bff;
    color: #fff;
}

.btn {
    -moz-user-select: none;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    display: inline-block;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    padding: 0.375rem 0.75rem;
    text-align: center;
    transition: color 0.15s ease-in-out 0s, background-color 0.15s ease-in-out 0s, border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
    vertical-align: middle;
    white-space: nowrap;
}
<label for=\"upload_file\" class=\"custom-file-upload btn btn-primary\"><i class=\"fa fa-cloud-upload\"></i> File Upload</label>
<input class=\"margin\" type=\"file\" formnovalidate id=\"upload_file\" name=\"file\" accept=\"*\">

要回复问题请先登录注册