Home >Web Front-end >CSS Tutorial >Regarding the ellipses that appear when CSS multi-line text overflows
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; /* 显示多少行 */ }
Extension
word-wrap
Keyword | Description | Default value | Value |
---|---|---|---|
Specifies the conditions for word wrapping | normal, line breaks at word hyphenation points. | break-word, break a line within a word. | |
Description | Default value | Value | |
---|---|---|---|
How to display text beyond the box | clip, Trim text. ellipsis, displays the ellipsis. string, displays the specified text. |
Description | Default value | Value | |
---|---|---|---|
How to treat blanks and whether to wrap lines | normal, 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.
Description | Default value | Value | |
---|---|---|---|
How to order child elements | inline-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
ellipsis | |
ellipsis git | |
1. Introduce the script file
<script src="https://cdn.jsdelivr.net/npm/ellipsis.js@0.1.3/ellipsis.js"></script>2. Use
var ell = Ellipsis({ lines: 3 }) var ele = document.getElementsByClassName('test') ell.add(ele)
Extension
It also has some configuration items. If not configured, the default value is used.
{ ellipsis: '...', // 默认显示的替代文本 debounce: 0, // 延迟多长时间后执行 responsive: true, // 是否有窗口大小改变时执行 className: '.clamp', // 默认操作具有这个类的元素。 lines: 2, // 默认只出现2行元素。 portrait: null, // 默认不改变,如果你想要在竖屏模式下有不同的行数, break_word: true // 默认截断单词。 }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!