Home > Web Front-end > CSS Tutorial > Regarding the ellipses that appear when CSS multi-line text overflows

Regarding the ellipses that appear when CSS multi-line text overflows

不言
Release: 2018-06-14 10:39:36
Original
1898 people have browsed it

This article mainly introduces relevant information on examples of ellipses appearing when CSS multi-line text overflows. The content is quite good. I will share it with you now and give it as a reference.

Ellipses appear when multi-line text overflows

This article recommends 2 methods.

1. css

tip: Only compatible with browsers with chrome kernel. ff is not supported.

.box {
    overflow: hidden; /* 溢出时不显示溢出的内容 */
    text-overflow: ellipsis; /* 发生溢出时使用省略号代替 */
    display: -webkit-box; /* chrome浏览器的私有属性。显示为box。 */
    -webkit-box-orient: vertical; /* 垂直排列元素 */
    -webkit-line-clamp: 2; /* 显示多少行 */
}
Copy after login

Extension

word-wrap

##word-wrapSpecifies the conditions for word wrapping normal, line breaks at word hyphenation points. break-word, break a line within a word. overflow-wrap, changed from word-wrap to overflow-wrap in css3
KeywordDescriptionDefault valueValue
text-overflow

KeywordDescriptionDefault valueValue##test-overflowwhite-space
How to display text beyond the box clip, Trim text. ellipsis, displays the ellipsis. string, displays the specified text.

Keywordswhite-spacebox-orient
DescriptionDefault value Value
How to treat blanks and whether to wrap linesnormal, blank will be ignored by the browser. pre, leave blank. nowrap, the text does not wrap. pre-wrap, keep blanks and wrap normally. pre-line, merge whitespace, retain newlines.

This attribute is not supported by browsers yet. You need to use the private properties of the respective browsers.

Keywordsbox-orientline-clamp
DescriptionDefault valueValue
How to order child elementsinline-axis, child elements are along the inline coordinate axis (mapped to the horizontal direction). horizontal, specifies that child elements are arranged from left to right on a horizontal line. vertical, arranges child elements vertically from top to bottom. block-axis, child elements are along the block axis (mapped to vertical). inherit, inherit the parent element.

Only browsers with chrome core support their own private properties.

How many rows of block-level elements are displayed.

2. jsThere are many ways to use js to control how overflow text is displayed. Here is a recommended script file: ellipsis.js

ellipsis.js

##NameLinkellipsis linkhttps://www.jsdelivr.com/package/npm/ellipsis.jsellipsishttps://cdn.jsdelivr.net/npm/ellipsis.js@0.1.3/ellipsis.jsellipsis githttps:// github.com/glinford/ellipsis.jsHow to use.

1. Introduce the script file

<script src="https://cdn.jsdelivr.net/npm/ellipsis.js@0.1.3/ellipsis.js"></script>
Copy after login

2. Use

var ell = Ellipsis({
    lines: 3
})
var ele = document.getElementsByClassName(&#39;test&#39;)
ell.add(ele)
Copy after login

Extension

It also has some configuration items. If not configured, the default value is used.

{
    ellipsis: &#39;...&#39;, // 默认显示的替代文本
    debounce: 0, // 延迟多长时间后执行
    responsive: true, // 是否有窗口大小改变时执行
    className: &#39;.clamp&#39;, // 默认操作具有这个类的元素。
    lines: 2, // 默认只出现2行元素。
    portrait: null, // 默认不改变,如果你想要在竖屏模式下有不同的行数,
    break_word: true // 默认截断单词。
}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the use of the greater than sign in CSS styles and the inheritance method in Css


The above is the detailed content of Regarding the ellipses that appear when CSS multi-line text overflows. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template