【问题标题】:How do I set the length of a string in a table to a certain length in a rails application?如何在rails应用程序中将表中字符串的长度设置为一定长度?
【发布时间】:2020-09-19 18:49:32
【问题描述】:

我的 index.html.erb 上有一个带有标题列的表格。这些标题很长,所以当我渲染我的页面时,表格在屏幕上水平地走得很远。这一切都在一条线上。 我如何设置它,以便在大约 6 个单词后进入另一行,在 6 个单词后,字符串被切断。桌子被圈住了!当用户访问单独的 show.html 页面时,可以阅读完整的描述

下面的一些代码

<td class="px-6 py-4 whitespace-no-wrap border-b border-gray-200">
   <div class="text-sm leading-5 text-gray-900"><%= article.title %></div>
</td>

【问题讨论】:

  • 字符是比单词更好的截断,并且会在渲染中创造更大的一致性。例如"As one who enjoys long words""Hippopotomonstrosesquipedaliophobics vehemently abhor such sesquipedalian responses"

标签: ruby-on-rails string-length tailwind-css


【解决方案1】:

我想你可以尝试计算你想要的字符数量并以此来限制,例如

<%= truncate(title, length:10) %>

但是如果你需要一些非常强大的东西来支持屏幕尺寸等,我很确定 css 可以帮助你 CSS text-overflow in a table cell?

【讨论】:

  • 谢谢!我最终在 CSS 中找到了一些有用的东西!干杯
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 2013-04-26
  • 2012-04-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多