Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: File input button #21829

Closed
leon opened this issue Jan 24, 2017 · 2 comments
Closed

Feature: File input button #21829

leon opened this issue Jan 24, 2017 · 2 comments

Comments

@leon
Copy link

leon commented Jan 24, 2017

<input type="file" /> has always been very hard to style.
I've seen that there is a .custom-file but this shows the filepath.
https://v4-alpha.getbootstrap.com/components/forms/#file-browser

What if you want the same look and feel as a button?

My proposal is to be able to style a file input as a btn.

What do you guys think?

Proof of concept
Check out this plunkr
https://plnkr.co/edit/feW4kk?p=preview

I've tested the button with successful results in:
Chrome 55
Safari 10
Firefox 49
IE Edge
IE 11
IE 10

The code if you don't want to look at the plunkr

<div class="btn btn-default btn-file">
  <input type="file" />
  Upload a file
</div>
.btn-file {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.btn-file input {
  position: absolute;
  top: 0;
  right: 0;
  max-width: 100%;
  min-height: 100%;
  margin: 0;
  opacity: 0;
  transform: translate(-100%, 0) scale(3);
  direction: ltr;
  cursor: pointer;
}

/* Hack for forcing webkit to show a cursor all the time */
.btn-file input::-webkit-file-upload-button {
  cursor: pointer;
}
@RusinovAnton
Copy link

#21812

/* Hack for forcing webkit to show a cursor all the time */
.btn-file input::-webkit-file-upload-button {
  cursor: pointer;
}

@mdo
Copy link
Member

mdo commented Jan 24, 2017

Going to pass on this given we have a custom file input and I don't think further divorcing it from browser default styling is a good idea for us to implement. I'd rather let folks set that kind of custom styling for themselves. Thanks though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants