Home > Web Front-end > CSS Tutorial > Why isn't my 'text-overflow: ellipsis' working?

Why isn't my 'text-overflow: ellipsis' working?

Barbara Streisand
Release: 2024-11-10 03:47:02
Original
238 people have browsed it

Why isn't my

Troubleshooting "text-overflow: ellipsis" Issue

The use of "text-overflow: ellipsis" aims to truncate text within an element, displaying "..." when the text reaches a specified limit. However, in some instances, this functionality might not work as expected.

In the example provided, it appears that "text-overflow: ellipsis" is not having the desired effect. To resolve this issue, ensure that the relevant styles have been applied correctly. In addition to "text-overflow: ellipsis," the CSS should include the following properties:

1. Overflow:

overflow: hidden;
Copy after login

2. Width or Max-Width:

width: [desired width];
max-width: [maximum width];
Copy after login

3. Display:

display: block;
Copy after login

4. White-Space:

white-space: nowrap;
Copy after login

A comprehensive CSS snippet that incorporates all these properties is provided below:

span {
    border: solid 2px blue;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 100px;
    display: block;
    overflow: hidden
}
Copy after login

By applying these styles, the "span" element will shrink in width as the window gets smaller, resulting in the truncation of text with ellipsis. Here's an example to illustrate how it works:

HTML:

<span>Test test test test test test</span>
Copy after login

The above is the detailed content of Why isn't my 'text-overflow: ellipsis' working?. For more information, please follow other related articles on the PHP Chinese website!

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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template