Html 在 asp:Button 中换行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5268354/
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
Wrap text within a asp:Button
提问by Coder 2
I was using a LinkButton and it had like lot of text in it which made it quite long. This was fine as the LinkButton wrapped the text onto the next line when it ran out of room.
我使用的是 LinkButton,它里面有很多文字,所以很长。这很好,因为 LinkButton 在空间不足时将文本包裹到下一行。
I then changed this to a standard asp:Button and the problem is the text doesn't wrap the button just becomes as long as the text. This is a problem because it forces the container it is within to be longer than I intended.
然后我将其更改为标准的 asp:Button,问题是文本没有包裹按钮,只是变得与文本一样长。这是一个问题,因为它迫使它所在的容器比我预期的要长。
Is there a way to make the text of the button wrap?
有没有办法让按钮的文本换行?
回答by wsanville
You can do that by setting a width and the CSS property white-space: normal
:
您可以通过设置宽度和 CSS 属性来实现white-space: normal
:
This goes in your <head>
这在你的 <head>
<style type="text/css">
.wrap { white-space: normal; width: 100px; }
</style>
And your button:
还有你的按钮:
<asp:Button ID="btn" runat="server" Text="some really breally long text that I want to wrap" CssClass="wrap" />
回答by Catto
<asp:Button ID="btn" runat="server" Text="some really breally long 
 text that I want to wrap" />
This question was helpful and wanted to point out if we want to break the text in a specific spot we could also by adding the within the text value.
这个问题很有帮助,想指出我们是否想在特定位置中断文本,我们也可以通过在文本值中添加 。
I also marked wsanville answer as useful.
我还将 wsanville 的答案标记为有用。
回答by jonezy
You should be able to set a width on the asp:button (width=100) and that should force the text to wrap.
您应该能够在 asp:button (width=100) 上设置宽度,并且应该强制文本换行。
回答by rick schott
There are some alternate solutions in this post that may be helpful:
这篇文章中有一些替代解决方案可能会有所帮助: