html - 如何更改输入文件按钮大小?

标签 html css file input resize

我正在使用不透明度方法对输入文件进行样式设置 - 实际输入文件按钮的不透明度为 0,在它前面,使用 z-index 是另一个输入(不透明度:1)。不幸的是,我希望我的可见按钮是方形图片(宽度:高度:1:1) - 并且不可见的输入文件始终是矩形(输入框和选择框的纵横比约为 1:10)。问题是 - 如何将输入文件按钮的大小调整为方形(或任何大小)以使整个可见按钮区域可单击(因为仅单击不可见按钮会导致打开浏览器窗口)。现在只有部分可见按钮是“可点击的”。

CSS:

   <style type="text/css">
   .upload {
        position:relative;
    width:100px;
   }

   .realupload {
    position:absolute;
    top:0;
    right:0;
    opacity:0.5;
    -moz-opacity:0.5;
    filter:alpha(opacity:0.5);
    z-index:2;
    width:100px;
   }

   form .fakeupload {
    background: url(images/bglines.png);
   }

   form .fakeupload input {
    width:0px;
   }

   </style>

和 html:

<form>
   <li class="upload">
    <div class="fakeupload">
        <input type="text" name="fakeupload" style="opacity: 0;"/>
    </div>
    <input type="file" name="upload" id="realupload" class="realupload" onchange="this.form.fakeupload.value = this.value;" style="font-size: 5px;" />
   </li>
   </form>

最佳答案

我们有一个类似的案例。

它不是非常优雅,但您可以尝试以下操作,而不是输入多个文件:

  • 增加输入的字体大小以增加按钮的宽度
  • 设置父相关元素overflow:hidden
  • (可选)将高度设置为 100%

demo here (基于 Scott 的演示)

只适用于 Firefox

关于html - 如何更改输入文件按钮大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9153354/

相关文章:

html - 奇怪的 :hover bug with z-index and img

html - 如何在底 Angular 的广告上显示链接文本

javascript - 单击空白区域时如何触发body.onclick

jquery - 第二次防止 CSS3 旋转

java - 计算 java 中的文件长度 : FileReader vs. File.length

html - 文本的背景颜色。之间的空间。线条宽度相同。在线填充

css - 关于 CSS3 translate3d 闪烁,查了很多答案,但似乎不走运

html - 调整页面大小时,所有事情都搞砸了

Java:将数组写入文本文件

java - 如何在流中查找字符串数组的值