Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make <input type="file"> element fill up its parent <div>

Tags:

html

css

HTML:

<div>
  <img src="some/path/" class="thumbnail" />
  <input type="file" class="image_upload" />
</div>

CSS:

div
{
  border: 2px solid #ccc;
  width: 50px;
  height: 50px;
  overflow: hidden;
}
.thumbnail
{
  width: 100%;
}
.image_upload
{
  opacity: 0;
  position: absolute;
}

I want <img> and <input type="file"> to overlap with each other and both fill up their parent <div>. How can I fix my CSS to achieve that?

like image 209
tamakisquare Avatar asked Dec 22 '11 20:12

tamakisquare


3 Answers

It is not possible to change the size of a file input. You could redesign the file-input and, but the size of the clickable area isn't modifiable.

Edit: Aaron shows a first trick, and I added the second one, so see this fiddle in which the whole image is clickable for the file input.

The trick is to set font-size to a large value, then opacity to zero and finally add overflow: hidden to the parent element.

like image 83
Yogu Avatar answered Oct 16 '22 11:10

Yogu


File input fields don't really play by the rules (or at least as you'd expect). To accomplish what it sounds like you're after, you've gotta get creative. Example: http://jsfiddle.net/ZTPCd/

like image 33
Aaron Avatar answered Oct 16 '22 10:10

Aaron


Its Possible.

Add this css for input type file

.My_CSS {
    opacity: 0; 
    border: none;
    border-radius: 3px;
    background: grey;
    position: absolute;
    left: 0px;    
    width: 100%;
    top: 0px;
    height: 100%;
}
like image 41
Dinesh Kanivu Avatar answered Oct 16 '22 11:10

Dinesh Kanivu