如何更改输入文件按钮的大小?
我正在使用不透明度方法处理输入文件样式 - 实际输入文件按钮的不透明度为 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>
I am working with styling input file with opacity method - real input file button has opacity 0 and in front of it, using z-index is another input (with opacity: 1). Unfortunatelly I want my visible button to be squared picture (width:height: 1:1) - and unvisible input file is always rectangular (input box and select box with aspect ratio about 1:10). Question is - how to resize input file button to be squared (or any size) to make whole visible button area clickable (because only clicking invisible button causes opening browser window). Now only part of on visible button is "clickable".
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>
And 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们也有过类似的案例。
它不是超级优雅,但您可以尝试如下操作,而不是放置多个文件输入:
如此处演示(基于在斯科特的演示中)
仅适用于火狐浏览器
We had a similar case.
It's not super elegant but instead of putting multiple file input you can try as following:
As in the demo here (based on Scott's demo)
Only works on Firefox
要缩短输入类型文件按钮可点击区域,您可以尝试使用此方法:
这将缩小输入类型文件的可点击区域。 (您可以使用transform:scale(x,y) - 其中x和y是适合您需要的数字。
请记住为移动设备或不同的浏览器添加适当的样式。
To shorten input type file button clickable area you can try to use this:
This will narrow the clickable area of input type file. (You can use transform: scale(x,y) - with x and y is number that will fits your need.
Remember to add proper styling for mobile devices or different browsers.
尝试使用“图像”输入类型?
否则,您必须确保在输入按钮上设置 display: block 参数。
try using the "image" input type?
Otherwise you'll have to be sure to set the display: block parameter on the input button.
问题可能在于格式错误的 HTML。 -- li 标签之外不能有表单标签。
这似乎对我来说效果很好...... 演示在这里
It's possible that the malformed HTML is the problem. -- You can't have form tags outside of li tags.
This seems to work fine for me..... Demo here