Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set input height 100% of parent

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.

like image 416
Dracco Avatar asked Jun 05 '13 07:06

Dracco


People also ask

How do I make my Div 100% height of my parents?

and set the content div to have a left margin of whatever the width of the navigation pane is. That way, the content's content is to the right of the navigation and you can set the navigation div to be 100% of the content's height.

How do you make an element 100% height?

Syntax: To set a div element height to 100% of the browser window, it can simply use the following property of CSS: height:100vh; Example: HTML.

What does height 100% do CSS?

height: 100% gives the element 100% height of its parent container. height: auto means the element height will depend upon the height of its children.


2 Answers

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.

like image 131
Jerska Avatar answered Sep 19 '22 07:09

Jerska


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.

like image 31
T30 Avatar answered Sep 21 '22 07:09

T30