Html 如何适应表格单元格中的文本框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4122645/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to fit textbox in the table cell
提问by user384080
.. been trying to fit the textbox (auto adjust the textbox width) within HTML table's cell but no luck.. can anyone please help? thanks
.. 一直试图在 HTML 表格的单元格中适应文本框(自动调整文本框宽度)但没有运气.. 任何人都可以帮忙吗?谢谢
What I have:
我拥有的:
<td>
<asp:TextBox ID="txtPrice" runat="server" style="width:100%"/>
</td>
回答by Kyle
"Textboxes" like <textarea>
are inline elements. You need to make this:
“文本框”就像<textarea>
是内联元素。你需要这样做:
HTML:
HTML:
<textarea class="myTextarea">
Content
</textarea>
CSS:
CSS:
.myTextarea
{
display: block;
width: 100%;
height: 100%;
}
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 :)
另外,你有一些我们可以看到的代码吗?textbox
不是有效的 HTML,所以我们不知道您要使用什么 :)
回答by Christian Kuetbach
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.
在我的测试中,它奏效了。
回答by surfer190
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
但是,左边有溢出,我会看看我能做些什么
回答by AndreKR
style="width: 100%; height: 100%;"
does not work?
style="width: 100%; height: 100%;"
不起作用?
回答by oezi
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.
设置你的“文本”(不管它是什么?你的意思textarea
或input type="text"
?)到100% width
,并hight
与它margin
为0,并设置padding
你的表芯的为0。