Home > Article > Web Front-end > Why isn't my 'text-overflow: ellipsis' working?
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;
2. Width or Max-Width:
width: [desired width]; max-width: [maximum width];
3. Display:
display: block;
4. White-Space:
white-space: nowrap;
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 }
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>
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!