如果没有剩下的空间可以完全显示它,则使文本不可见

发布于 2025-02-10 16:37:51 字数 121 浏览 2 评论 0 原文

我正在开发一个网站,有一个地方有报价,我希望,如果无法完全显示文本(基本上某些单词很好,我都不是整个Div看不见,因为我不希望切断一些单词,而我不想使用溢出之类的东西:滚动; ,所以我如何解决此问题:)

I'm developing a website and there is a place that has quotes in it I want it that if the text can't be displayed fully (basically if some words well get out off the div) I wan't the whole div to be invisible because I don't want some words to be cut off and I don't want to use things like overflow: scroll; so any ideas how can I fix this :)

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

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

发布评论

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

评论(1

嗫嚅 2025-02-17 16:37:51

scrollwidth 是元素的宽度,也是不可显示的内容。

OffsetWidth 是唯一可显示的内容宽度。


因此,如果 scrollwidth OffsetWidth 不同,则意味着这意味着溢出!

if (divQuote.scrollWidth > divQuote.offsetWidth) {
      // put a display none on divQuote (css)
      // or use your logic to go to the next quote
}

有用的文档:
scrollwidth: https://developer.mozilla.org/en-us/docs/web/api/element/scrollwidth
offsetWidth: https://develoverer.mozilla.org/en-us/docs/web/api/api/htmlelemt/htmlelemt/htmlelement/offsetwidthththththththththththththththththththththththththththth < /p>

“ https://i.sstatic.net/2dnf9.png” rel =“ nofollow noreferrer”>

scrollWidth is the width of elements with also not showable content.

and offsetWidth is the only showable content width.


so if the scrollWidth is different than offsetWidth, this means that is overflowing!

if (divQuote.scrollWidth > divQuote.offsetWidth) {
      // put a display none on divQuote (css)
      // or use your logic to go to the next quote
}

useful docs:
scrollWidth: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
offsetWidth: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth

enter image description here

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