0

Why does display: inline-block not work properly for <input type="file">?

I would like the width of the element to be as wide as the content it's made of (button + text). But there's always some free space at the end of the text.

Why? And can this be fixed?

input[type="file"] {
  display: inline-block;
  min-width: auto;
  width: auto;
  background-color: lightgray;
}
<input type="file">

Screenshot: https://ibb.co/pWWdQ0y

JOKKER
  • 502
  • 6
  • 21
  • You may want to check this out for a cross browser solution: https://stackoverflow.com/questions/572768/styling-an-input-type-file-button/25825731#25825731 – Techuila Apr 03 '21 at 17:29

2 Answers2

0

I do not know whether it is eligible for you, however it is possible to set width through CSS:

input[type='file'] {
  width: 180px;
  background-color: lightgreen;
}
<input type="file">
StepUp
  • 36,391
  • 15
  • 88
  • 148
-1

Try giving the width in percentage, it will work.

input[type='file'] {
  width: 36%;
  background-color: lightgray;
}