Home > Web Front-end > CSS Tutorial > How to Implement Proper Ellipsis (Mac Style) within Resizable Elements?

How to Implement Proper Ellipsis (Mac Style) within Resizable Elements?

Susan Sarandon
Release: 2024-10-29 03:38:29
Original
783 people have browsed it

How to Implement Proper Ellipsis (Mac Style) within Resizable Elements?

Proper Ellipsis Implementation in the Heart of Text (Mac Style)

In the pursuit of a seamless user experience, the problem of mid-text ellipsis ("...") presents a challenge. Our aim is to implement this feature within a resizable element, maintaining its functionality as the element expands.

The solution lies in a two-pronged approach. Firstly, assign the full string to a custom data-* attribute within the HTML:

<span data-original="your string here"></span>
Copy after login

Secondly, utilize JavaScript to read this data and dynamically adjust the innerHTML of the element in response to load and resize events. The following function exemplifies this approach:

<code class="javascript">function start_and_end(str) {
  if (str.length > 35) {
    return str.substr(0, 20) + '...' + str.substr(str.length-10, str.length);
  }
  return str;
}</code>
Copy after login

Customizable values allow you to adapt to various objects, ensuring optimal display at different widths. Enhance the user experience by incorporating an abbr-tag on the ellipsis or tooltip, providing users with additional context upon hover:

<abbr title="simple tool tip">something</abbr>
Copy after login

By skillfully applying these techniques, you can confidently offer users a robust and visually appealing ellipsis solution that complements the flexibility of resizable elements.

The above is the detailed content of How to Implement Proper Ellipsis (Mac Style) within Resizable Elements?. 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