user384080
user384080

Reputation: 4692

how to fit textbox in the table cell

.. been trying to fit the textbox (auto adjust the textbox width) within HTML table's cell but no luck.. can anyone please help? thanks

What I have:

<td>
  <asp:TextBox ID="txtPrice" runat="server" style="width:100%"/>
</td>

Upvotes: 12

Views: 40119

Answers (5)

tread
tread

Reputation: 11098

This works for me:

<asp:TextBox ID="txtPrice" runat="server" width=100%"/>

However, there is overflow to the left I'll see what I can do

Upvotes: 3

Kyle
Kyle

Reputation: 67194

"Textboxes" like <textarea> are inline elements. You need to make this:

HTML:

<textarea class="myTextarea">
Content
</textarea>

CSS:

.myTextarea
{
   display: block;
   width: 100%;
   height: 100%;
}

Example for you here.

And an updated example for you here. (With margins added and a table for you to see it working in)

Also, do you have some code we can see? textbox isn't valid HTML so we have no idea what you're trying to use :)

Upvotes: 12

oezi
oezi

Reputation: 51797

set your "textbox" (whatever that is... do you mean textarea or an input type="text"?) to 100% width and hight and it's margin to 0 and set the padding of your table-cell to 0.

Upvotes: 0

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

Try this:

<td>
<textarea style="width:100%;height:100%;margin:0;padding:0;" rows=1 cols=1>
    text!
</textarea>
</td>

in my tests, it worked.

Upvotes: 4

AndreKR
AndreKR

Reputation: 33678

style="width: 100%; height: 100%;" does not work?

Upvotes: 1

Related Questions