c# - asp :label text using word-break on only long words? 上的断行

标签 c# html css asp.net

我有一个 asp:label 必须适合它的父容器

问题是有时文本是一个连续的字符序列,没有空格。

我正在寻找 CSS 行为来在单词太长时断开单词,但不会断开可以转移到它下面的行的小单词。

这是我最初拥有的:

<asp:Label ID="lblTextComments" runat="server"></asp:Label>

这会产生:

some normal text that 
breaks onto a new line

但这发生在一个长词上:

someverylongtextwithoutanywhitespaceatalldoesnotcausealinebreaktohappen

这会在网页外运行。

我使用了这个 CSS 样式解决方案:

<asp:Label ID="lblTextComments" runat="server" Style="word-wrap: normal; word-break: break-all;" ></asp:Label>

这正确地打破了长词:

someverylongtextwithoutanywh
itespaceatalldoesnotcauseali
nebreaktohappen

但这打破了我希望移到下一行的小词:

some normal text tha 
t breaks onto a new line

最佳答案

试试这个 CSS:

word-wrap: break-word;

关于c# - asp :label text using word-break on only long words? 上的断行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38839501/

相关文章:

c# - 为 C# 使用包装器类

javascript - 将图像/视频从 html 获取到 java servlet 作为 new File()

javascript - 尽管横幅的大小是固定的,但 Adsense 仍显示空白广告

angularjs - 带有计时器的成功动画 - Ionic 框架上的 Sweet Alert

css - 如何保持具有动态内容的元素的圆形形状?

c# - Visual Studio 2015 在 Text Visualizer 上截断长字符串

c# - 我应该如何序列化包含大量对象列表的对象?

html - 将表格行显示为列表

c# - 将每个 CSV 文件记录转换为单独的 JSON 文件

javascript - 专注于浏览器