Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncate text in input type = file

Tags:

css

Is it possible to truncate text in input type="file", I mean, when I select file if filename is too long it should be truncated. I tried to apply text-overflow: ellipsis; but nothing changes.

like image 599
Alen Avatar asked Oct 30 '13 22:10

Alen


3 Answers

If you specify a fixed width for the input, most browsers should truncate it themselves. If not, you can still use text-overflow: ellipsis but it won't make any difference until you use it with two additional properties and also with width:

input[type=file] {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 150px;
}
like image 56
matewka Avatar answered Nov 15 '22 19:11

matewka


Are you trying to actually truncate it, or change the display? You cannot actually set the value, because that is a security risk -- no browser allows that. To change the display of the value, you could do what matewka suggests. For more control over the appearance, you could also hide the input and replace it with a <span> containing the value in question, like this: http://jsfiddle.net/TexasBrawler/jrJm2/2/

like image 37
elixenide Avatar answered Nov 15 '22 20:11

elixenide


How to truncate filename for input type file:

If you have a container around your file input you can set it to display: flex; and it will truncate with ellipsis.

Try messing with the width in the example below and trying removing display: flex; to see the text overflow the container with no truncation.

.file-input-container {
  display: flex;
  width: 160px;
  padding: 10px;
  background-color: #CCC;
}
<div class="file-input-container">
  <input type="file" />
</div>
like image 1
StefanBob Avatar answered Nov 15 '22 20:11

StefanBob