Applying css on asp.net FileUpload Control's Browse Button only

前端 未结 4 2126
礼貌的吻别
礼貌的吻别 2020-12-15 06:46

I have a FileUpload Control like this


Now I want to apply css only on the Bro

相关标签:
4条回答
  • 2020-12-15 07:25

    Styling an input tag with type="file" requires a bit of work, browsers don't behave similarly when you try to style them unfortunately.

    There are a few methods of doing so though:

    • http://www.quirksmode.org/dom/inputfile.html
    • http://www.appelsiini.net/projects/filestyle
    0 讨论(0)
  • 2020-12-15 07:29

    This is possible you can change the FileUpload control using following code.

    Step 1: Change FileUpload control with this code on aspx page

    <label class="file-upload">
        <span><strong>Upload Image</strong></span>
        <asp:FileUpload ID="FileUpload1" runat="server" >
        </asp:FileUpload>
    </label>
    

    Step 2: now add below CSS code into your main CSS file

    .file-upload {
        display: inline-block;
        overflow: hidden;
        text-align: center;
        vertical-align: middle;
        font-family: Arial;
        border: 1px solid #124d77;
        background: #007dc1;
        color: #fff;
        border-radius: 6px;
        -moz-border-radius: 6px;
        cursor: pointer;
        text-shadow: #000 1px 1px 2px;
        -webkit-border-radius: 6px;
    }
    
    .file-upload:hover {
            background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1));
            background: -moz-linear-gradient(top, #0061a7 5%, #007dc1 100%);
            background: -webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%);
            background: -o-linear-gradient(top, #0061a7 5%, #007dc1 100%);
            background: -ms-linear-gradient(top, #0061a7 5%, #007dc1 100%);
            background: linear-gradient(to bottom, #0061a7 5%, #007dc1 100%);
            filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0);
            background-color: #0061a7;
    }
    
    /* The button size */
    .file-upload {
        height: 30px;
    }
    
    .file-upload, .file-upload span {
            width: 90px;
    }
    
    .file-upload input {
                top: 0;
                left: 0;
                margin: 0;
                font-size: 11px;
                font-weight: bold;
                /* Loses tab index in webkit if width is set to 0 */
                opacity: 0;
                filter: alpha(opacity=0);
    }
    
    .file-upload strong {
                font: normal 12px Tahoma,sans-serif;
                text-align: center;
                vertical-align: middle;
    }
    
    .file-upload span {
                top: 0;
                left: 0;
                display: inline-block;
                /* Adjust button text vertical alignment */
                padding-top: 5px;
    }
    

    It's done.

    0 讨论(0)
  • 2020-12-15 07:43

    apparently you cannot style them directly with CSS but you can "hack" a new style into them - read the following article for details

    http://www.quirksmode.org/dom/inputfile.html

    0 讨论(0)
  • 2020-12-15 07:50

    check out this video, you must add an extra button but it works https://youtu.be/_O9YVO-Z-Xo

    0 讨论(0)
提交回复
热议问题