Set input height 100% of parent

32,792

Solution 1

You cannot set height:100%; on an element if the parent hasn't a set height.

Just set td { height: 30px; } and it should work.

Actually, my last link was not working. After a few researches, it seems that you cannot achieve what you want without some JavaScript. But as you said, you tried to use JavaScript, so I assume this should be what you're looking for : Answer to the same kind of question (Have a look at its fiddle.) Seemingly, you won't have the choice.

Solution 2

You can set position:absolute to the input.

Here a Fiddle example (note that you must also set a width for the <td> that contains the input):

input{
    position:absolute;
    top:0px;
    height:100%;
}
td{
    position:relative;
    width:200px;
}

It works also with <input type="submit"> and <div>.

Tested on Firefox, Chrome and Edge, For Explorer, you should set a min-height to the input to make it at least usable.

UPDATE: For Dracco, here a Fiddle implementing your example.

Solution 3

Somehow setting table height to 100% works.

table {
  height: 100%;
}

input {
  height: 100%;
}
<table>
  <tr>
    <td> 1<br> 1 </td>
    <td> <input> </td>
  </tr>
</table>
Share:
32,792
Dracco
Author by

Dracco

I am a web developer and programmer, passionate by the web technology. My passion means, that I love to spend my free time working on my projects and learning new things. I find it easy to learn new technologies and I do enjoy that, as broadening my knowledge is my aim. Being in love with both programming and web development, I started to concentrate on JavaScript, as it connects both of the above in the one great technology. In my free time I often experiment with JavaScript trying to master if in every bit. I also keep myself updated about CSS and HTML, because if something is easily achievable with CSS, it should probably not be done in JavaScript. My biggest concern for the web is performance. Not only it allows for a smooth runtime, but also saves the battery on portable devices, which is a crucial factor nowadays. Well built web application also loads faster, which has a significant impact on a mobile broadband. To summarize, I am a JavaScript Engineer and a performance maniac. I love a clean, easily maintainable code, which saves the time for both the developer, and the browser.

Updated on July 09, 2022

Comments

  • Dracco
    Dracco almost 2 years

    I have a little problem with setting input (type text) height to fit 100% of parents (td) height. I even tried to iterate through every input and set it height manually with jQuery, but it takes quite a lot of time (site I am working on has a lot of cells) and still doesn't work on IE 7 and 8 (I have to make site work under those too). Here is a sample: http://st8.eu/test.html It would be greatly appreciated if anybody knows any solution/hack.