What is the best approach for showcasing overflowing text in tables in a manner that is user-friendly?

I am seeking a solution for dynamically loading data in a table, where I want to wrap long text with ellipsis and display the full content elegantly on hover. Currently utilizing HTML and CSS for this purpose, I have encountered an issue. Even when the text is not large, the styling still appears on mouse hover. Is there a workaround for this problem? Alternatively, would using JavaScript provide a better solution?

For reference, here is a link to the plunker I have created. You can observe in column three that the text is not extensive, there is no ellipsis applied, yet the styling persists on hover. Any assistance on resolving this issue would be greatly appreciated!

https://plnkr.co/edit/cDOxlXRK6QfynVdpCbCT?p=preview

Below is the CSS code being used:

/* Styles go here */
table td.text {
  max-width: 10px;
}

table td.text span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: inline-block;
  max-width: 100%;
}
table td.text:hover span{
    border: 2px solid #000000;
    background-color: #ffffff;
    padding: 5px;
    overflow: visible;
    white-space: normal;
    height: auto;
    /* just added this line */
    position:absolute;
}

table td.text:hover span:empty {
    display:none;
}

Here is the HTML code:

<table>
  <thead>
    <tr class="text-center">
      <th>Column1</th>
      <th>Column2</th>
      <th>Column3</th>
      <th>Column4</th>
    </tr>
  </thead>
  <tr>
    <td class="text"><span>Lorem Ipsum is simply dummy text...</span></td>
    <td class="text"><span>Lorem Ipsum is simply dummy text...</span></td>
    <td class="text"><span>Lorem </span></td>
    <td class="text"><span></span></td>
  </tr>

</table>

Answer №1

It's no surprise that the styling continues to take effect. Without any conditions based on the length of the data in the table, the overflow will remain hidden until triggered by a mouseover event as instructed.

If it were up to me, I'd suggest creating a JavaScript function to check if there is overflowing content before applying any specific CSS classes (initially setting a default class that can later be changed to an overflow class if necessary). This task can be easily accomplished using jQuery.

You might find this question useful: javascript css check if overflow

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

Is it possible to exclusively target a child div using JavaScript in CSS, without affecting the parent div?

I'm in the process of developing a calendar feature where users can select a specific "day" element to access a dropdown menu for time selection. The functionality is working fine, but I've encountered an issue. When a user selects a time from th ...

What is the best way to send multiple requests for the same file and retrieve the necessary response in PHP using jQuery AJAX?

var postID = $post->ID; $.ajax({ type: "POST", url: "<?php echo get_template_directory_uri();?>/b.php", data:{postID:postID}, dataType: 'json', success: function(re ...

How to use JavaScript to hide an element (field) in XPages

In XPages, I understand that only editable fields are able to retrieve values from context. My question is: how can I hide a field using CSS or JavaScript in XPages while still being able to get its value from the context? Many thanks ...

Adjusting Font Size on a Website: A Quick Guide

I recently started diving into the world of building web pages. To practice, I created a simple site but for some reason, I'm having trouble changing the text size. When I try to remove the background image code, it seems to work fine, but I can&apos ...

The node.js fs module reports that the object does not support the appendFile method

I am currently developing a node js application for educational purposes, where each operation is being logged into a file named log.txt The logging module contains the following code: var fs = require('fs'); function write(data, filename) { ...

Swap out the div block with a new one

I am currently facing an issue with my JavaScript code. The code is supposed to remove block1 and replace it with block2 when an onclick function is triggered. function buyerclick() { div = document.getElementById('block2'); div.style.displa ...

What could be causing my HTML footer to not grow from its borders?

Hello there, I need assistance with an HTML document I am working on. Can you explain why my footer is not expanding to the edges even though I have set the width to 100%? Please help. Please note that the code provided is incomplete, and for the full cont ...

I am looking to integrate a predefined equation using JavaScript

I need help implementing a specific formula in JavaScript that involves dealing with 5 input fields. Below is the HTML code (apologies for the language, it is in a different locale): <div class="row" style="padding:10px 12px;"> &l ...

only one Collapsible will be open at any given moment

// In the code snippet below, there are three Collapsibles. When one is clicked, it expands, but in order to close it again, you have to click on that particular text. I want to implement a change: if any of the three Collapsibles are already open and I cl ...

Having trouble transferring form data from a React.js form to a Flask API, as it is not permitting submission to MongoDB

I am currently working on a project to create a user form using react.js, python (Flask), and mongodb. Unfortunately, I am facing an issue where none of the input data is being sent to the Flask backend. Does anyone know how I can troubleshoot this problem ...

Tips for avoiding the "Confirm Form Resubmission" pop-up?

Is there a way to clear form data after submission in order to prevent errors from appearing upon page refresh? For reference, please see the image below (taken from Chrome): The dialog box displays the following message: The page you're trying t ...

Error with vue html interpolation due to ReferenceError

After adding the following code snippet to my public/index.html: <script type="text/javascript"> rg4js("apiKey", "<%= VUE_APP_RAYGUN_API_KEY %>"); rg4js("enableCrashReporting", true); </script> ...

When I zoom in, h4 and h5 headers expand and extend beyond their boundaries

Currently, I am working on designing forms for this specific website. Everything appears to render properly at normal zoom levels. However, when I adjust the zoom in or out slightly, issues arise where the h4's and h5's are no longer centered wit ...

Oops! The module "rxjs/Subject" seems to be missing the exported member "Subject"

Here is the code I'm working with: import { Subject } from 'rxjs/Subject'; Upon importing this, an error occurs: rxjs/Subject" has no exported member 'Subject'. I am unable to fix this issue. Does anyone have a solution? ...

How can I change the color of the fa-star symbol from its default yellow to white?

When I set color:white; or use the classes icon-light or icon-white, all font-awesome-icons turn white except for fa-star which stubbornly remains yellow. I've tried various methods to override the CSS, including using !important in inline-styling on ...

Keeping an object in a multidimensional array based on its ID in Angular 4/Ionic 3 without removing it

Exploring a complex data structure: [{ propertyoutsideid: 1, items: [ {itemId: 1, something: 'something'}. {itemId: 2, something: 'something'}. {itemId: 3, something: 'something'}. ] },{ prope ...

Setting the root route in express.js is a simple process that involves defining the

As a newcomer to express.js, I'm facing a challenge that has been puzzling me for almost 4 hours. My express server is meant to serve a build of a react app. To determine whether the user is not a bot, I am utilizing the useragent library. The code ...

Application.js encountering a mistake that needs attention

I've recently delved into developing a new game using nodejs, but I'm facing a strange issue in which I'm unable to use require in the app.js file. This is perplexing to me because I've successfully implemented require in other similar ...

AngularJS ng-table filter for exact matching

I am currently working with the following function: function updateTable(lines) { // console.log("dit is de filter", $scope.filter); lines = lines || []; $scope.tableParams = new NgTableParams({ filter: $scope.filter, ...

Interactive jQuery element featuring an image gallery displayed within a translucent black overlay on a webpage

My goal is to add a jQuery popup with an image that appears automatically when a website loads. I envision the popup creating a black transparent overlay, similar to this example. While setting up the basic popup was straightforward, integrating the image ...