javascript - 如何显示文件名等于高度和宽度输入
问题描述
我使用 bootstrap 4,我的问题是当我放置一个长名称的文件时,名称会从输入中消失
解决方案
如果您可以提供代码示例会更好,但本质上您将需要设置大小 -height
并width
在您的input
和使用overflow:hidden
它。
编辑:由于您使用的是 Bootstrap 4 及其输入文件实现,假设您的 HTML 与他们的示例中提供的一样:
<div class="input-group mb-3">
<div class="custom-file">
<input type="file" class="custom-file-input" id="inputGroupFile01">
<label class="custom-file-label" for="inputGroupFile01">Choose file</label>
</div>
</div>
并且您正在使用 JS 将名称附加到 .custom-file-label 元素,根据他们的文档,您必须将溢出隐藏设置为您的标签:
.custom-file-label {
overflow:hidden;
}
在这里小提琴:https ://jsfiddle.net/frked93u/7/
如果您需要更优雅的解决方案,我建议在标签上使用溢出省略号和额外的填充,因此当标签用完时,它不会剪切中间文本,而是在文件名的末尾附加省略号空间。
.custom-file-label {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right:75px;
}
在这里小提琴:https ://jsfiddle.net/frked93u/9/
将来,如果您使用代码示例和/或工作小提琴更新您的问题,而不仅仅是提供有关您正在使用的框架的详细信息,您将更快、更准确地获得帮助。
推荐阅读
- javascript - jQuery找到最接近的给定类
- python - 如何在 Paramiko SSH 客户端上增加回滚缓冲区?
- chisel - 你如何测试 RawModules?
- html - 位置固定元素在滚动时移动
- postgresql - Postgresql物化视图有很多刷新效率吗?
- swift - 无法在 macOS Mojave 应用程序中模拟击键
- sql - 从表中查找与确切输入匹配的行
- ruby-on-rails - `initialize':getaddrinfo:名称解析暂时失败(SocketError)
- javascript - 为什么当我对 src URL 进行硬编码时会显示我的 img,而当我以编程方式分配它时却没有?
- git - 不小心从我的电脑上删除了我的项目