如果句子横跨屏幕,如何在句子中插入空格?

发布于 2024-08-02 12:42:28 字数 196 浏览 2 评论 0原文

我的 asp.net web 项目中有一个用户控件。

它显示博客文章的标题。如果标题太长,它会拉伸包裹的表格并破坏页面布局。

如果文本中不包含空格,有没有办法可以在 40 个字符后截断文本?

我如何检查任何地方是否存在空格,如果不存在则插入一个空格。

我正在寻找“最佳实践”,因为我确信这是网络应用程序的常见问题。

I have a user control in my asp.net web project.

It displays the title of a blog post. If the title is too long, it will stretch the wrapped table and ruin the page layout.

Is there a way I can chop the text after 40 characters IF the text doesn't contain a space in it?

How would I check for the existance of a space anywhere, and if not exist insert a space.

I'm looking for the 'best practise' as I'm sure this is a common problem for web apps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

似狗非友 2024-08-09 12:42:28

在这种情况下,最佳实践是重新访问您的页面布局设计。

听起来你设计的东西对于网络来说有点太不灵活了。用户始终可以选择调整浏览器大小......这肯定会破坏您在此处描述的布局。

强迫他们动手是一种糟糕的用户体验。

创造一些灵活的东西,无论长度如何,都能优雅地表现是更好的选择......

The best practice in this case would be to re-visit your page layout design.

It sounds like you've designed something that is a little too in-flexible for the web. The user always has the option to resize the browser...and that could definitely break your layout as you describe it here.

Forcing their hand is a poor user experience.

Creating something flexible that behaves gracefully no matter the length is the better option...

丑丑阿 2024-08-09 12:42:28

> 标签就是为此目的而设计的。还有一些其他 html 实体可以帮助解决此问题。本质上,它向浏览器表明,如果该行太长,这将是一个可以中断的地方。

您可以在这里阅读更多信息:

http://www.quirksmode.org/oddsandends/wbr.html< /a>

The <wbr/> tag was designed for this purpose. There are also some other html entities that can help with this. Essentially it suggests to the browser that this would be an ok place to break if the line gets too long.

You can read more here:

http://www.quirksmode.org/oddsandends/wbr.html

草莓酥 2024-08-09 12:42:28

除非我过度简化问题:

overflow: hidden;

应该可以解决问题。

Unless I am over-simplifying the problem:

overflow: hidden;

should do the trick.

很酷不放纵 2024-08-09 12:42:28

TextFormatFlags 可能会有所帮助你。您可能想使用 WordEllipses 或 WordBreak 做一些事情。

TextFormatFlags may help you. You may want to do something with WordEllipses or WordBreak.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文