gpt4 book ai didi

css - 获取空白 nowrap 样式的 "..."延续

转载 作者:行者123 更新时间:2023-11-28 18:52:43 32 4
gpt4 key购买 nike

我在一段文本上成功应用了 white-space: nowrap。我想知道如果文本被 nowrap 样式截断,是否有可能在文本末尾获得标准的“...”。这是 CSS 可以解决的问题吗?还是我需要 javascript?

谢谢。

最佳答案

Firefox(可能还有其他一些)支持:

text-overflow: ellipsis;

但无论如何它都不是跨浏览器的。为了获得跨浏览器的东西,您需要使用 javascript。我过去这样做的一种方法是:

<div class="text">
text goes here
<div class="ellipsis">...</div>
</div>

.text {
position : relative;
}

.text .ellipsis {
display : none;
}
.text.long .ellipsis {
display : block;
position : absolute;
right : 0px;
background : #FFF;
}

那么你的 js 就是这样的(使用 jQuery):

$( '.text' ).each( function(){
var $this = $( this );
$this[ ( $this.width() > $this.outerWidth() ) ? 'addClass' : 'removeClass' ]
( 'long' );
} );

关于css - 获取空白 nowrap 样式的 "..."延续,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8844625/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com