简体   繁体   English

块级别相当于文本溢出:省略号

[英]Block level equivalent of text-overflow:ellipsis

I want to offer small blurbs that will disappear into ellipsis if they are too long for the container div they are put into. 我想提供一些小的模糊,如果它们太长而不能放入容器中,它们会消失在省略号中。 I would like to offer a visual indication that there is more text if a user follows the link to the article. 我想提供一个视觉指示,如果用户跟随文章的链接,则会有更多文本。 I don't want to use an ellipse image, but I can use jQuery if required. 我不想使用椭圆图像,但如果需要我可以使用jQuery。 My preference is to do it entirely in CSS3, if possible. 如果可能的话,我的偏好是完全在CSS3中完成。

I found the text-overflow:ellipsis property / value, combined with overflow:hidden and white-space:nowrap allow for a single-line version of this, but what about multi-lines? 我找到了文本溢出:省略号属性/值,结合溢出:隐藏和空白:nowrap允许这个单行版本,但是多行呢? vs. in my case. 在我的情况下。

Will these, or another property / value pair allow for this to be done in strictly CSS? 这些或其他属性/值对是否允许在严格的CSS中完成?

Any help is appreciated. 任何帮助表示赞赏。

Try this Fiddle not mine 试试这个小提琴 不是我的

or there is the dotdotdot plugin 或者有dotdotdot插件

Given HTML mark-up along the following lines: 给定HTML标记沿着以下行:

<div class="multiline"><!-- long string of text... --></div>

<div class="singleline"><!-- long string of text... --></div>​

And the following CSS: 以下CSS:

div {
    /* aesthetic stuff, such as width, max-width, border, line-height etc... */
    overflow: hidden; /* required to hide the overflow */
    position: relative;  /* required to position the pseudo-element */
}
div.multiline {
    max-height: 12em; /* defines the 'overflow point' */
}
div.singleline {
    max-height: 1.5em;
}
div::after {
    content: '...';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 2em;
    text-align: center;
    background-color: #fff;
}

JS Fiddle demo . JS小提琴演示

While this broadly achieves your intent, in compliant browsers, it does have the problem of not lining up the generated 'ellipsis' with the end of the visible text, unfortunately. 虽然这大致实现了您的意图,但在兼容的浏览器中,它确实存在不会将生成的“省略号”与可见文本的末尾排列在一起的问题。

remove css 删除css

 white-space:nowrap;

and set a height to your div 并为你的div设置一个高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM