tags:

views:

58

answers:

3

Say, I have the following unordered list. The button has width: auto. How do I style the elements, so #textField would stretch as much as possible, so the width of #textField and the button would add up to 100%?

<ul>
  <li>
    <input id="textField" type="text" /><input type="button" />
  </li>
</ul>
A: 

How about this?

<ul>
  <li>
    <input id='textField' style='width: 80%'/><input type='button' style='width: 20%'/>
  </li>
</ul>
Goutham
I don't want to explicitly set the width for any of them.
William
A: 
<ul>
  <li style="position:relative; width:100%;">
    <input id="textField" type="text" style="position:absolute; left:0px; right:80px" />
    <input type="button" value="Submit" style="position:absolute; right:0; width:auto" />
  </li>
</ul>

Adjust right:80px to set margin between textbox and button;

Jeaffrey Gilbert
Interesting idea, but that didn't work. When you make an element position absolute, you need to explicitly set the position and size, which isn't what I want. I want the text field to be resizable.
William
I defined `left` and `right` to make it anchored to its container (must have `position:relative`) not to define its size, it is resizable.
Jeaffrey Gilbert
First of all, for some reason the `right` property doesn't work for me (in Safari). Secondly, I don't want to define the `right` property, as I would like it to automatically adjust with the `button` to the right.
William
A: 

I ended up using a table and stretch the cell that contains the text field:

<ul>
  <li>
    <table>
      <tr>
        <td width="100%"><input width="100%" id="textField" type="text" /></td>
        <td><input type="button" width="auto" /></td>
      </tr>
    </table>
  </li>
</ul>
William
no no no no no!!1 :( These kinds of solutions make me cry :(
Litso
Do you have a better suggestion, Litso?
William