Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fit textbox in the table cell

Tags:

html

css

asp.net

.. 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>
like image 734
user384080 Avatar asked Nov 08 '10 09:11

user384080


People also ask

How do I fit a text box to a table in HTML?

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.

How do I make text fit in a text box?

Fit text automaticallyOn the Text Box Tools Format tab, in the Text group, click Text Fit, and do one of the following: To reduce the point size of text until there is no text in overflow, click Shrink Text On Overflow. To shrink or expand text to fit in the text box when you resize the box, click Best Fit.

How do I make text fit in a table cell?

On the Layout tab, in the Cell Size group, click in the Table Column Width box, and then specify the options you want. To make the columns in a table automatically fit the contents, click on your table. On the Layout tab, in the Cell Size group, click AutoFit, and then click AutoFit Contents.


3 Answers

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

like image 62
tread Avatar answered Sep 22 '22 13:09

tread


"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 :)

like image 12
Kyle Avatar answered Oct 17 '22 07:10

Kyle


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.

like image 4
Christian Kuetbach Avatar answered Oct 17 '22 07:10

Christian Kuetbach