简体   繁体   English

输入类型文件超过其宽度

[英]input type file exceeds its width

I have styled a file selector but the problem is it exceeds its max-width from the parent container我已经设计了一个文件选择器,但问题是它超出了父容器的最大宽度

Everything works fine here but run this code on browser you'll see that the input type file will exceed its limit这里一切正常,但在浏览器上运行此代码,您会看到输入类型文件将超出其限制

在此处输入图片说明

I have also attached my code我还附上了我的代码

 .inputcontainer { width:500px; margin:0 auto; padding:0; } .filess { text-align:center; width:200px; margin:auto; border:none; position:relative; } .filess .file_upload { max-width:150px; width:100%; height:35px; padding-top:6px; background:#f55282; color:#fff; display:inline-block; margin:0 auto 20px; cursor:pointer; font-size:19px; } .filess .file_upload input[type="file"] { position:absolute; height:100%; width:100%; opacity:0; top:0; left:0; cursor:pointer; } .filess span { float:left; text-align:center; margin:auto; display:inline-block; } .filess span.delt_head { float:right; cursor:pointer; }
 <div class="inputcontainer"> <div class="filess"> <span class="delt_head"><i>Delete</i></span> <span class="file_upload"><input type="file" /> Choose a file</span> </div> </div>

Any help will be appreciated任何帮助将不胜感激

There might be a problem with overflow try overflow:hidden for the file element.溢出可能有问题 try overflow:hidden file元素。

so that it will wrap around its parent container.以便它将环绕其父容器。

 .inputcontainer { width:500px; margin:0 auto; padding:0; } .filess { text-align:center; width:200px; margin:auto; border:none; position:relative; } .filess .file_upload { max-width:150px; width:100%; height:35px; padding-top:6px; background:#f55282; color:#fff; display:inline-block; margin:0 auto 20px; cursor:pointer; font-size:19px; } .filess .file_upload input[type="file"] { position:absolute; height:100%; width:100%; opacity:0; top:0; left:0; cursor:pointer; overflow:hidden; } .filess span { float:left; text-align:center; margin:auto; display:inline-block; } .filess span.delt_head { float:right; cursor:pointer; }
 <div class="inputcontainer"> <div class="filess"> <span class="delt_head"><i>Delete</i></span> <span class="file_upload"><input type="file" /> Choose a file</span> </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM