Home > Web Front-end > CSS Tutorial > How to Display Ellipsis in a Span with Hidden Overflow in CSS?

How to Display Ellipsis in a Span with Hidden Overflow in CSS?

Mary-Kate Olsen
Release: 2024-10-26 22:39:31
Original
247 people have browsed it

How to Display Ellipsis in a Span with Hidden Overflow in CSS?

Displaying Ellipsis in a Span with Hidden Overflow

In CSS, the overflow property determines what happens when an element's content overflows its bounds. In the given scenario, the CSS for a span element hides any overflowing content. This results in the content being cut off, as observed in the code snippet.

To address this issue, you can utilize the text-overflow property, which controls how overflowing text should behave. By setting text-overflow to ellipsis, you can specify that any overflowing text should be replaced with an ellipsis (...). This will allow you to display a portion of the text within the span while indicating that there is more.

Here's how you can modify your CSS to achieve the desired result:

<code class="css">span {
  display: inline-block;
  width: 180px;
  overflow: hidden !important;
  text-overflow: ellipsis;
}</code>
Copy after login

This updated CSS will display the text within the span element, up to 180 pixels in width. Any remaining text will be replaced with an ellipsis.

The above is the detailed content of How to Display Ellipsis in a Span with Hidden Overflow in CSS?. 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