How to make parts of a div element resize automatically?

Posted by vladimir on Stack Overflow See other posts from Stack Overflow or by vladimir
Published on 2010-03-17T16:33:57Z Indexed on 2010/03/17 17:01 UTC
Read the original article Hit count: 278

Filed under:
|
|
|

I'm trying to create a small html fragment (a div element) consisted of three parts: a label, textbox, and a button.

Within that div element the label would be on the left (autosized), the button would be on the right (again, autosized) and the textbox should take up all remaining space within the parent div element.

This is what I've tried (assuming I want my div to be 400 pixels wide):

<div style="width:400px">
    <div style="float: left">Label</div>
    <input style="width:100%">  <!-- doesn't work -->
    <button type='button' style='float: right'>Click</button>
</div>

The trouble is, my textbox does not get resized automatically. Add 'width=100%' to the textbox doesn't work.

What would be the way to make it take up all remaining space between the label and the button? Ideally it should be done just by applying some styles, not by introducing new elements.

(I guess the issue isn't related only to div element, but that just happens to be my work scenario.)

© Stack Overflow or respective owner

Related posts about html

Related posts about div