【问题标题】:Is there a way I can change the width of text which is on second line?有没有办法可以更改第二行文本的宽度?
【发布时间】:2022-11-16 14:13:33
【问题描述】:

我有一个要求,我想动态减少第二行文本的宽度,

this is first line text
this is second line text

所以上面的文字我想看起来像这样

this is first line text
this is ...

我想在悬停在 div/span 上的其他一些图标上使用其余的空间。

目前我依靠减少跨度的宽度,我已经探索了椭圆和线夹属性,但这种组合适用于不在第二行或最后一行的两条线。所以我得到的结果是这样的 -

this is first
line text ...

任何帮助表示赞赏,在此先感谢。

【问题讨论】:

  • CSS 中的 :nth-child() 可能会有用。要是你把你试过的东西贴出来就好了,这样我就可以测试一下了。
  • 让我创建一个小提琴并将其发布在这里。
  • 这个 answer on Meta 涵盖了在帖子中创建代码 sn-ps 而不是使用外部站点,并且对于试图帮助您的读者来说更方便。

标签: javascript jquery multiline


【解决方案1】:

将下面的 css 添加到第二行,你可以设置特定的宽度,这样你就可以实现这个

.secondline {
   width: 100px;
   display: -webkit-box;
   webkit-line-clamp: 1;
   webkit-box-orient: vertical;
   overflow: hidden;
   text-overflow: ellipsis;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-11
    • 1970-01-01
    • 2012-03-29
    • 2023-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多