The text is spilling over onto two separate lines

In my table, I have implemented styles that display only the first line of text. However, I would like to show at least two lines if available. For example, if the text has four lines, I want to display the first two lines from the start and reveal the remaining lines when the user hovers over the text.

Below is the current CSS code I am using:

.cortar {
  width: 135px !important;
  height: 20px;
  padding: 20px;
  border: 1px solid blue;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  transition: all 1s;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}
.cortar:hover {
  width: 100%;
  white-space: initial;
  overflow: visible;
  cursor: pointer;
}

How can I modify the code to achieve the desired effect?

Thank you!

EDIT 1

Here is a snippet of my HTML:

<p-table [columns]="columnasIndicadoresOperacion>
    <ng-template pTemplate="colgroup" let-columns>
        <colgroup>
           <col *ngFor="let col of columns">
        </colgroup>
    </ng-template>
    <ng-template pTemplate="header" let-columns>
       <tr>
          <th *ngFor="let col of columns">
              {{col.header}}
          </th>
       </tr>
     </ng-template>
     <ng-template pTemplate="body" let-rowData let-columns="columns">
        <tr>
           <td class="cortar"*ngFor="let col of columns">
               <p [title]="rowData.indicadores[col.field]">
                   {{rowData.indicadores[col.field]}}
               </p>
           </td>
        </tr>
     </ng-template>
 </p-table>

Answer №1

Here is a suggestion to use -webkit-line-clamp:

.cortar {
  width: 135px !important;
  height: 20px;
  padding: 20px;
  border: 1px solid blue;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  transition: all 1s;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
   /* from here */
   box-sizing: border-box;
   display: -webkit-box;
   -webkit-line-clamp: 2;
   -webkit-box-orient: vertical;
}

If you are dealing with an scss file that needs compilation, consider adding autoprefixer. I encountered this issue while working with angular.

.cortar {
  width: 135px !important;
  height: 20px;
  padding: 20px;
  border: 1px solid blue;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  -webkit-transition: all 1s;
  -moz-transition: all 1s;
  transition: all 1s;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
   box-sizing: border-box;
   display: -webkit-box;
   -webkit-line-clamp: 2;
    /* autoprefixer: off */
    webkit-box-orient: vertical;
    /* autoprefixer: on */
}

Check out a demo code here

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

Tips for updating the navigation bar content to reflect the current page and display the correct links

Greetings! I have a navigation bar in my application and utilize the root to switch between components. Here is my .html code: <nav class="navbar navbar-expand-lg navbar-light bg-light"> <img src="assets/pictures/AVtech.png" ...

Maximizing Bootstrap card size in Angular4: A step-by-step guide

How can I make Bootstrap cards resizable on top of other elements when clicked on an icon to make it full screen and overlay on other cards? detail.component.html <div class="card card-outline-info" > <div class="card-header bg-info"><h5 ...

Locating the top 3 largest values in an HTML data table and highlighting them in red

Issue Description: I am working with data that displays the electricity consumption of different buildings in HTML tables. There is a possibility that these tables may contain duplicate values. With the use of jQuery, I am seeking a method to identify an ...

The code functions perfectly on JSfiddle, but for some reason it halts when implemented on

Unfortunately, the code that was working perfectly on JSfiddle seems to be encountering issues when implemented on a regular HTML site. The content loads fine but there seems to be an error with the preview function after selecting an image. We have colla ...

What is the best way to make a JavaFX WebView the same size as the entire scene?

My goal is to have a JavaFX WebView that automatically resizes to fit the scene upon startup. Currently, I am focused on setting the initial size properly. @Override public void start(Stage stage) { try { Scene scene = new Scene(createWebViewP ...

Having trouble with running npm start for the Angular2 QuickStart on Windows 10?

While attempting to replicate the Angular official tutorial for Windows 10 (https://angular.io/guide/quickstart), I encountered an error when running the "npm start" command: 0 info it worked if it ends with ok 1 verbose cli [ 'C:\\Program ...

Utilizing multiple modules with a shared component leads to errors in Angular 2

There is a shared component called GoComponent that I need to utilize in two different modules: FindPageModule and AddPageModule. Unfortunately, when I include it in the declarations of both "FindPageModule" and "AddPageModule," I encounter an error: f ...

Exploring the Differences Between ionViewWillEnter and ionViewDidEnter

When considering whether to reinitiate a cached task, the choice between ionDidLoad is clear. However, when we need to perform a task every time a view is entered, deciding between ionViewWillEnter and ionViewDidEnter can be challenging. No specific guid ...

What effective method can be used to transfer data between two sibling Angular components?

I'm diving into Angular and have a question about the best approach for enabling communication between two components in my application. I know there are various strategies available and I want to figure out what would work well for my specific scenar ...

What steps should I take to create a horizontal parallax scrolling effect on my website

I am seeking to create a unique parallax effect on my website's background that scrolls horizontally instead of vertically. I attempted to make adjustments to the jQuery code below, which was originally for vertical scrolling, but was unsuccessful in ...

Avoid clicking in areas outside the perimeter of the blue circle in the SVG

Is there a way to restrict clicking outside the blue circle? The goal is to only allow opening by clicking on the svg itself, This includes everything, even white space inside the svg. How can this be achieved in the code? The current behavior is that ...

A guide to updating a button in Angular:

Currently, I have implemented a directive that displays 3 tabs at the bottom. However, I am curious to know if it is possible to swap out "exterior" for "interior" based on whether I am on the exterior or interior page. For example, when on the exterior ...

Retrieving information from a JSON reply within an Angular 2 service

I am currently utilizing a service in angular 2 that retrieves JSON data from an API (). The code for fetching the data is depicted below: getImages() { return this.http.get(`${this.Url}`) .toPromise() .then(response => response.json() ...

Error: The module 'AppModule' has encountered an unexpected value 'CalendarComponent'. To resolve this issue, please include a @Pipe/@Directive/@Component annotation

Recently, I started working with Angular 2 and wanted to incorporate the 'schedule' feature from Primeng. To do so, I installed its package and added the calendarComponent in my app.module.ts file as shown below: import { BrowserModule } from &a ...

Working with CSS styles for the <datalist> element

I currently have a basic datalist drop-down menu and I am looking to customize the CSS to match the style of other fields on my website. However, as someone new to web design, I am unsure of how to go about this process. Check out the code here: http://j ...

Utilize jQuery and AJAX to send a request when an object is loaded

For quite some time now, I've been struggling with a particular issue and despite numerous attempts to find a solution, I still haven't been successful. It seems that the function $("#id").load(function [...]); just won't work for me. Here ...

Tips for updating the styles within a class for Angular 6 dynamically

Currently, I am able to update the button design using ng-container. Here is a snippet of the code: <ng-container *ngIf="isDisabled;"> <button class="bot-btn-disabled" (click)="confirm()" [disabled]=this. ...

How can I transfer user input to a service method in Angular?

My goal is to capture user input and pass that value into a service method to retrieve data related to the input and present it. (The getApplicantById method fetches data from the database in Postman.) Here's the code I've been working on: compon ...

Create a search functionality within the <mat-menu> element in Angular

In my Angular application, I have a mat-menu set up like this: <mat-menu #menu="matMenu"> <div *ngFor="let id of services"> <button mat-menu-item *ngIf="id !== service_id" (click)="d ...