Skip to content

Instantly share code, notes, and snippets.

@ryanve
Last active October 28, 2015 00:32
Show Gist options
  • Select an option

  • Save ryanve/db138eac14a5b62f5666 to your computer and use it in GitHub Desktop.

Select an option

Save ryanve/db138eac14a5b62f5666 to your computer and use it in GitHub Desktop.
CSS module for semantic inline [type=file] inputs
.browse {
display: inline;
font-size: inherit;
}
.browse__input {
display: inline-block;
position: absolute;
@include px-rem(padding, .1);
@include px-rem(margin, 0, -.5);
height: 0;
width: 0;
overflow: hidden;
&::before {
// hack to respect the `cursor` style
white-space: pre;
content: " ";
display: block;
}
}
// enabled or disabled
.browse__input[class] {
opacity: .0001;
}
.browse__label {
display: inline-block;
}
.browse__input:enabled,
.browse__input:enabled + .browse__label {
cursor: pointer;
}
@ryanve
Copy link
Copy Markdown
Author

ryanve commented Oct 26, 2015

example markup

Or <label class="browse"><input tabindex="0" class="browse__input" type="file"><span class="browse__label">browse</span></label> your computer.

@ryanve
Copy link
Copy Markdown
Author

ryanve commented Oct 28, 2015

alternate markup

<fieldset class="browse">
    <input id="browse" class="browse__input" type="file" tabindex="0">
    <label for="browse" class="browse__label button">Browse</label>
</fieldset>

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