Show tooltip exclusively when the text being shown ends with "..."

Currently, I am dealing with a table that consists of 5 columns and over a thousand rows. I need help with implementing a specific feature in one column, which can then be replicated to the other columns if successful. Due to varying text lengths within these columns, some of the texts may need to be truncated with "..." at the end. To achieve this, I have included the CSS property "text-overflow: ellipsis". My goal is to display a tooltip saying "HELLO everyone" only for the texts that are truncated because they are too long to fit inside the column.

Here is the HTML code for one of the five columns in my table:

<ng-container matColumnDef="title">
  <th mat-header-cell *matHeaderCellDef class="table-header">
    Title
  </th>
  <td 
    pTooltip="HELLO everyone" 
    (click)="toggleSeeMore(element)" 
    mat-cell 
    *matCellDef="let element" 
    class="title-column-news"
  >
    <div [style]="styleTitle(element.showSeeMore)">{{ element.title }}</div> 
      <div *ngIf="element.showSeeMore" style="margin-top: 10px">
        <span>
          <div [style]="styleTitle(element.showSeeMore)">{{ element.summary }}
            <a 
              style="color:var(--limegreen); text-decoration: none;" 
              target="_blank" 
              [href]="element.file"
            >
              See more
            </a>
          </div>
        </span>   
      </div>
    </td>
  </ng-container>

For styling purposes, here is the CSS code:

td {
  color: var(--textLightGrey);
  border-bottom: 1px solid var(--textLightGrey);
  padding: 10px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

Answer №1

For more information, check out this link

div {
  line-height: 20px;
}

#data {
  width: 100px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#data:hover {
  overflow: visible;
  white-space: normal;
  width: auto;
  position: absolute;
  background-color: #FFF;
}

#data:hover+div {
  margin-top: 20px;
}

<div>1: ONE</div>
<div id="data">2: Two Two 

div {
  line-height: 20px;
}

#data {
  width: 100px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

#data:hover {
  overflow: visible;
  white-space: normal;
  width: auto;
  position: absolute;
  background-color: #FFF;
}

#data:hover+div {
  margin-top: 20px;
}
<div>1: ONE</div>
<div id="data">2: Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two </div>
<div>3: THREE</div>
<div>4: Four</div>

Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two Two 3: THREE 4: Four

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Uib-Dropdown functionality is not functioning properly when placed within the body of an HTML view

After correctly installing the following dependencies: "ui-bootstrap": "0.12.2", "ngAnimate": "1.5.5", "AngularJs": "1.5.5 I encountered an issue with creating a dropdown menu in my HTML view. Despite no visible errors and successful implementati ...

Saving data between refreshes in AngularJS can be achieved by utilizing services or local

In my application, I have a single object stored in $rootScope. I need to find a way to save its state when the user refreshes the app either by pressing F5 or manually. While I've come across examples using $cookies in Angular, they only allow for sa ...

Tips on how to position a expanding textarea in line with buttons

I need assistance with aligning a textarea that is growing to the left, and action buttons positioned on the right side of the textarea. My goal is to have the action buttons aligned at the bottom, level with the expanding text area. Here is the code snip ...

How can you center a webpage and make it occupy 60% of the screen?

I was attempting to design a website where the main content takes up 60% of the body. This is what I tried initially: body { align-items: center; text-align: left; justify-content: center; width: 60%; } Unfortunately, this approach did not work ...

Enhance your AngularJS application with advanced security features and implement a local storage

I have implemented an AngularJS application that utilizes angular ui-router for routing. Despite my efforts to enhance security, I encountered some challenges: To manage user authentication, I store tokens and user roles in local storage, redirecting ...

Why is it that I am unable to directly set a number attribute to null, but I am able to do so if it is the result of a conditional statement?

One may wonder why TypeScript doesn't complain when I write the following code: return { Price: value.rawPrice === null ? null : value.rawPrice } Yet it presents issues with this code: return { Price: null } This is particularly puzzling because ...

What is the most effective method for linking css and js files?

Assuming your website's domain is domain.com, and you have the following directories and files: - index.php <panel> - panel.php <css> - style.css <js> - jQuery.js In index.php, you can reference a css file like "css/style.css" or " ...

The 'connectedCallback' property is not found in the 'HTMLElement' type

After taking a break from my project for a year, I came back to find that certain code which used to work is now causing issues: interface HTMLElement { attributeChangedCallback(attributeName: string, oldValue: string, newValue: string): void; con ...

Activate hover effect on desktop screen (excluding tablets and phones) by utilizing media queries

Applying hover state styling to a div can be done like this: div { &:hover { color: red !important; border: 3px solid red !important; } } To exclude iPads and other tablets from this CSS style, you can util ...

Backend development for an Ionic application

As a newcomer to Ionic and Angular, I am currently working on basic features like tabs and tables. One specific task I am trying to achieve is creating a dynamic timetable that can be updated from a remote server. I want the app's timetable to refresh ...

Issue with maintaining fixed positioning of css elements while scrolling

I'm currently working on a school project and I seem to be encountering an issue with the positioning of the slider I created. Specifically, I am having trouble getting the bottom fixed position for it. The problem arises when scrolling the page, as t ...

What is the procedure for updating or adding data to a JSON file with angularJS?

After successfully creating a local JSON file and retrieving data from it using app.controller('appCtrl', function($scope, $http){ $http.get('employees.json').success(function(data){ $scope.employees=angular.fromJson(data.employee ...

The unexpected behavior of rxjs withLatestFrom

import { of, Subject, interval } from 'rxjs'; import { tap, startWith, map, delay, publishReplay, publish, refCount, withLatestFrom, switchMap, take } from 'rxjs/operators'; const source$ = new Subject(); const res ...

Error: Issue with accessing the 'get' property of an undefined value (Resolved issue with incompatible imports not functioning)

Encountering an issue while attempting to execute the karma TS spec file. Despite all modules and imports functioning properly without conflicts, the error persists. I've tried incorporating component.ngOninit() into beforeEach() and it(), but to no a ...

CSS declarations that have not been acknowledged or acknowledged

While working on a client's stylesheet today, I came across the following code: p { -webkit-hyphens: auto; -webkit-hyphenate-character: "\2010"; -webkit-hyphenate-limit-after: 1; -webkit-hyphenate-limit-before: 3; -moz-hyphens: manual; orphans: ...

Tips for linking two project routes in NodeJS and incorporating React (I am interested in invoking React within the NodeJS project)

I'm in the process of linking two projects, one using reactJS and the other NodeJS. Currently, NodeJS is running smoothly on localhost:3000. Next, I want to call a React application which redirects to port localhost:3001. How can I seamlessly connect ...

The HTML file's script tag does not function properly

I am facing an issue with using the script tag in my HTML files. For example, I am trying to create a photo gallery using HTML, CSS, and JS but the script part of my code doesn't seem to work. Here is the code snippet, can anyone spot any syntax or l ...

Utilize the designated version of Jasmine for optimal performance

I recently cloned a project that specifies Jasmine: 1.3.1 in its package.json file. In my other projects, I have Jasmine version 2.3.2 installed globally using npm install -g jasmine. npm view jasmine version 2.3.2 Unfortunately, there are compatibility ...

Learn how to incorporate additional rows into a table by pressing the plus button within the table with the help of Angular

I require some assistance. I am looking to dynamically generate a row after clicking on the plus button using angular.js. The newly created row should contain an ID and model generated dynamically. Here is an overview of my code: <table class="table ta ...

Choose just one column within an HTML table

Is there a way to easily select the text of a single column from an HTML table using just the mouse pointer? Imagine you have a table that looks something like this: https://i.sstatic.net/n3lZR.png When trying to select only the text in the Lastname col ...