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

不言
Release: 2018-06-14 10:39:36
Original
1799 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-wrap Specifies 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
Keyword Description Default value Value
text-overflow

Keyword Description Default value Value ##test-overflow white-space
How to display text beyond the box clip, Trim text. ellipsis, displays the ellipsis. string, displays the specified text.

Keywords white-space box-orient
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.

Keywords box-orient line-clamp
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

##Name Link ellipsis link https://www.jsdelivr.com/package/npm/ellipsis.js ellipsis https://cdn.jsdelivr.net/npm/ellipsis.js@0.1.3/ellipsis.js ellipsis git https:// github.com/glinford/ellipsis.js How to use.

1. Introduce the script file

Copy after login

2. Use

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

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 // 默认截断单词。 }
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!