11

Using bootstrap, I created input-group with a button and input type='file'.

It is working fine everywhere except IE9. On IE9 the browse button is being cropped from right side.

Demo: http://jsbin.com/alESiBo/6/edit

Code:

<div class="input-group">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">
      <i class="icon-upload-alt"></i>&nbsp;Upload
    </button>
  </span>
  <input id="fileField" class="form-control" name="fileField" type="file" />
</div>

Output:

IE 9.0.8112.16421

enter image description here

Chrome 31.0.1650.63 m

enter image description here

IE Version with snapshot:

enter image description here

Zain Shaikh
  • 6,013
  • 6
  • 41
  • 66
  • I tested your link on IE10; click event on "Browse.." button doesn't even work. It works when I do double click on text field left to "Browse..." button. – joy Jan 19 '14 at 16:49
  • Yup, that is another issue. – Zain Shaikh Jan 20 '14 at 07:27
  • You might check out this question here: http://stackoverflow.com/questions/12260680/changing-style-of-file-browse-button – dlane Feb 12 '14 at 15:50
  • @dward I dont want to change the style of browse button. I am already using `bootstrap` styling. I just need it to appear properly in IE9. – Zain Shaikh Feb 13 '14 at 04:06
  • The browse button looks fine for me in IE9 - in that it isn't outside the wrapping container. http://silvarismarketing.com/traders/dward/browse.JPG – dlane Feb 13 '14 at 14:19
  • I am using the same exact version except I am on Update Version 9.0.10 and I do not see this issue. – Ryan Wheale Feb 16 '14 at 22:48
  • I too am unable to reproduce this issue using version 9.0.8112.16421 Update 9.0.21 or 9.0.24. I guess it's possible it was a bug in one or two updates, but I image the percentage of people using that exact version is rather low. – Alexander O'Mara Feb 17 '14 at 03:24
  • If you read the answer below, you'll get to know something you don't know by now. – Zain Shaikh Feb 21 '14 at 12:13
  • @ZainShaikh Did you manage to solve this issue? – Chris Gunawardena Feb 27 '14 at 00:02

5 Answers5

0

What you are seeing ( the grey part ) is the 'browse..' part of the file upload in IE9. This is 'just the way it is' for the bootstrap css. As other answers have shown, if you do not like this, yeah, just need to have a look into making your own.

Add this in your head tag to prevent further mismatches though...

<meta http-equiv='X-UA-Compatible' content='IE=edge'/>

Most common is to set this control hidden ( I agree it always looks awful and inconsistent ) and 'trigger' it from your own fake button.

Lots of great links from other answers.

Rob Sedgwick
  • 5,216
  • 4
  • 20
  • 36
0

Like Rob Sedgwick said in his answer this is just the way the control looks in IE, and styling it is not really allowed.

But… you can cheat: make the file input disappear, and create your own fake input. Then redirect the relevant events using JS.

HTML

<div class="input-group">
  <span class="input-group-btn">
    <button class="btn btn-default" type="button">
      <i class="icon-upload-alt"></i>&nbsp;Upload
    </button>
  </span>
  <input id="fileField" class="form-control" name="fileField" type="file" />
  <span class="form-control form-control-overlay" id="fileFieldOverlay">Choose file</span>
</div>

CSS

.form-control[type="file"] {
  margin-bottom: -100%;
  opacity: 0;
}

.form-control-overlay {
  /* style, if you want */
  cursor: pointer;
}

Javascript

var fileFieldEl = document.getElementById("fileField");
var fileFieldOverlayEl = document.getElementById("fileFieldOverlay");

// On change of file selection, update display
fileFieldEl.onchange = function(ev) {
  // remove file path; it's a fake string for security
  fileFieldOverlayEl.innerText = ev.target.value.replace(/^.*(\\|\/)/, '');
};

// Redirect clicks to real file input
fileFieldOverlayEl.onclick = function() {
  fileFieldEl.click();
};

Run the code: http://jsbin.com/alESiBo/16/edit

Community
  • 1
  • 1
Nelson Menezes
  • 2,036
  • 14
  • 15
0

add one more class :

bootstrap.css:3296

.input-group {position: relative; display: table; border-collapse: separate; width: 100%;}

try this may be it will be help you out.

Rajnish
  • 94
  • 2
  • 2
  • 10
0

Your code seems to work fine in IE9. http://fiddle.jshell.net/XCN83/1/show/

So, make sure your compatibility mode is not on. (see red circle in the attached image)

If not, some other css you have is affecting it, use the dev tools inspector to find styles applied to the file input box and it's parents working your way up.

enter image description here

Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
-1

I will suggest to use your own custom CSS to give same look and feel across the browser and same behavior across the browser. I have used similar approach to take care of this issue in my project. Following are same details also link of JSBIN for live demo.

HTML Code:

<!--Import button-->
    <div class="fileinput-button import-modal-select-file-btn" title="Import file">
        <!--Name of button -->    
        <span>Upload</span>
        <!-- Upload file control-->
        <input id="importFileUploadFileId" type="file" name="file" onchange="uploadFile(this);" />
        <!-- Any hidden field; Generally needed when upload button is part of form-->
        <input type="hidden" name="request" value="value"/>
    </div>

CSS Code (Please customize as per your need):

.fileinput-button {
border-radius: 5px;
padding-left: 10px;
padding-right: 10px;
background-color: #e7e9eb;
border: 1px solid #454b59;
font-family: "Gill Sans","Gill Sans MT","Helvetica Neue",Helvetica,Arial,sans-serif;
color: #454b59;
font-weight: lighter;
font-size: 16px;
cursor: pointer;
overflow: hidden;
position: relative !important;
background-image: none;
height: 30px;
outline: none;
height: 28.5px;
line-height: 28.5px;
}


.fileinput-button input {
position: absolute;
top: 0;
right: 0;
margin: 0;
opacity: 0;
filter: alpha(opacity=0);
transform: translate(-300px, 0) scale(4);
font-size: 16px;
direction: ltr;
cursor: pointer;
}

.import-modal-select-file-btn {
width: 50px;
}

Following is live JSBIN link for your reference. http://jsbin.com/EWIGUrEL/1/edit

Hope it may help.

joy
  • 3,669
  • 7
  • 38
  • 73
  • .(class) input is not supported by IE9 – ArmaGeddON Feb 14 '14 at 09:23
  • 1
    @KID: What are you talking about? Class selectors were in the original CSS v1 spec and every notable browser has supported them for at least fifteen years (I'm sure IE5 did, IE9 certainly does). See [Class selectors#Browser Compatibility](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors#Browser_compatibility). That said, IE9 had incompatible support for [filter](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) and required `-ms-transform` rather than [transform](https://developer.mozilla.org/en-US/docs/Web/CSS/transform). – Adam Katz Feb 24 '14 at 00:34