Asp.net

在 asp:Button 中換行

  • December 9, 2014

我使用的是 LinkBut​​ton,裡面有很多文字,這讓它變得很長。這很好,因為 LinkBut​​ton 在空間用完時將文本包裹到下一行。

然後,我將其更改為標準的 asp:Button,問題是文本不換行,按鈕的長度與文本一樣長。這是一個問題,因為它迫使它所在的容器比我預期的要長。

有沒有辦法讓按鈕的文本換行?

您可以通過設置寬度和 CSS 屬性來做到這一點white-space: normal

這在你的<head>

<style type="text/css">
   .wrap { white-space: normal; width: 100px; }
</style>

還有你的按鈕:

<asp:Button ID="btn" runat="server" Text="some really breally long text that I want to wrap" CssClass="wrap" />
<asp:Button ID="btn" runat="server" Text="some really breally long 
 text that I want to wrap"  />

這個問題很有幫助,並想指出如果我們想在特定位置打破文本,我們也可以通過在文本內添加值。

我還將 wsanville 的答案標記為有用。

引用自:https://stackoverflow.com/questions/5268354