Styling an input type=“file” button

后端 未结 30 2083
终归单人心
终归单人心 2020-11-21 11:50

How do you style an input type=\"file\" button?

30条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 12:13

    Here is a solution, that also shows the chosen file name: http://jsfiddle.net/raft9pg0/1/

    HTML:

    
    
    File: -
    

    JS:

    $(function() {
        $("input:file[id=file-upload]").change(function() {
            $("#file-upload-value").html( $(this).val() );
        });
    });
    

    CSS:

    input[type="file"] {
        display: none;
    }
    
    .custom-file-upload {
          background: #ffffd;
          border: 1px solid #aaa;
          border-top: 1px solid #ccc;
          border-left: 1px solid #ccc;
          -moz-border-radius: 3px;
          -webkit-border-radius: 3px;
          border-radius: 3px;
          color: #444;
          display: inline-block;
          font-size: 11px;
          font-weight: bold;
          text-decoration: none;
          text-shadow: 0 1px rgba(255, 255, 255, .75);
          cursor: pointer;
          margin-bottom: 20px;
          line-height: normal;
          padding: 8px 10px; }
    

提交回复
热议问题