Home >Web Front-end >CSS Tutorial >Why Doesn't 'text-overflow: ellipsis' Work on My Span Element?
"text-overflow: ellipsis" Not Functional
When attempting to use "text-overflow: ellipsis" to truncate text within a element, the ellipsis does not appear when the window size is reduced.
Solution
To enable "text-overflow: ellipsis" functionality, it is necessary to include the following CSS properties in addition to "text-overflow":
Example Code
span { border: solid 2px blue; white-space: nowrap; text-overflow: ellipsis; width: 100px; display: block; overflow: hidden }
Explanation
In the provided example, the element is given a width of 100px and the overflow property is set to "hidden," ensuring that any excess content is hidden within the element's boundaries. The display property is set to "block" to force the element to occupy a rectangular block of space. Finally, the white-space property is set to "nowrap" to prevent line breaks within the text.
With these properties applied, the "text-overflow: ellipsis" property becomes functional, truncating the text within the element and adding an ellipsis (...) when the window size is reduced to a point where the text exceeds the element's width.
The above is the detailed content of Why Doesn't 'text-overflow: ellipsis' Work on My Span Element?. For more information, please follow other related articles on the PHP Chinese website!