When using `text-overflow: ellipsis`, the font-awesome icons are not displayed

I am experiencing an issue with a table containing font-awesome icons in the cells. I have implemented resizable table columns using plain JavaScript. The cell content is hidden when it overflows, and an ellipsis ("...") is displayed:

td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

The Issue: After resizing the columns to hide the content and then expanding them again, all icons disappear except for the first one.

Expected Outcome: The icons should reappear when the column is expanded again.

Please view the snippet below to observe the problem. Any assistance would be greatly appreciated! Thank you.

(function makeTableHeaderResizable() {
  // clear resizers
  Array.prototype.forEach.call(
    document.querySelectorAll('.table-resize-handle'),
    function(elem) {
      elem.parentNode.removeChild(elem);
    }
  );

// create resizers
  var thElm;
  var startOffset;
  Array.prototype.forEach.call(
    document.querySelectorAll('table th'),
    function(th) {
      th.style.position = 'relative';

      var grip = document.createElement('div');
      grip.innerHTML = ' ';
      grip.style.top = 0;
      grip.style.right = 0;
      grip.style.bottom = 0;
      grip.style.width = '5px';
      grip.style.position = 'absolute';
      grip.style.cursor = 'col-resize';
      grip.className = 'table-resize-handle';
      grip.addEventListener('mousedown', function(e) {
        thElm = th;
        startOffset = th.offsetWidth - e.pageX;
      });

      th.appendChild(grip);
    }
  );

  document.addEventListener('mousemove', function(e) {
    if (thElm) {
      thElm.style.width = startOffset + e.pageX + 'px';
    }
  });

  document.addEventListener('mouseup', function() {
    thElm = undefined;
  });
})();
/* text-overflow: ellipsis is likely causing the issue here */
td, th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table {
  table-layout: fixed;
  border-top: 1px solid black;
  width: 100%;
}

/* styling */
th {
  border-right: 1px dotted red;
}
th {
  height: 50px;
}
td {
  border: 1px solid black;
}
tr {
  border-left: 1px solid black;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<h5>Drag the right border of the th elements and make the cells smaller. All fa-icons but the first have disappeared when you make the cells wider again.</h5>
<table>
  <thead>
    <tr>
      <th>Column</th>
      <th>Column</th>
      <th>Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        text works normally
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
    </tr>
  </tbody>
</table>

Answer №1

To make the fa class display inline, you simply need to set the display property to inline. Here is a demonstration on how to do it (view working fiddle here):

td .fa {
  display: inline !important;
}

Answer №2

Here's a CSS suggestion for you: make sure to set the table width to 100% or define a maximum width.

 td, th {
    white-space: -o-pre-wrap; 
    word-wrap: break-word;
    white-space: pre-wrap; 
    white-space: -moz-pre-wrap; 
    white-space: -pre-wrap; 
}

Answer №3

Simply remove the display property from the fa class within the td.

.fa {
   display: inline-block;
}

In order to achieve this, change it to

.fa {
  display: unset;
}

as shown below:

/* Eliminate the default inline-block of font awesome .fa class */
td i {
  display: unset !important;
}

Here is a demonstration.

(function makeTableHeaderResizable() {
  // clear resizers
  Array.prototype.forEach.call(
    document.querySelectorAll('.table-resize-handle'),
    function(elem) {
      elem.parentNode.removeChild(elem);
    }
  );

  // create resizers
  var thElm;
  var startOffset;
  Array.prototype.forEach.call(
    document.querySelectorAll('table th'),
    function(th) {
      th.style.position = 'relative';

      var grip = document.createElement('div');
      grip.innerHTML = '&nbsp;';
      grip.style.top = 0;
      grip.style.right = 0;
      grip.style.bottom = 0;
      grip.style.width = '5px';
      grip.style.position = 'absolute';
      grip.style.cursor = 'col-resize';
      grip.className = 'table-resize-handle';
      grip.addEventListener('mousedown', function(e) {
        thElm = th;
        startOffset = th.offsetWidth - e.pageX;
      });

      th.appendChild(grip);
    }
  );

  document.addEventListener('mousemove', function(e) {
    if (thElm) {
      thElm.style.width = startOffset + e.pageX + 'px';
    }
  });

  document.addEventListener('mouseup', function() {
    thElm = undefined;
  });
})();
/* text-overflow: ellipsis is likely causing the issue here */

td,
th {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table {
  table-layout: fixed;
  border-top: 1px solid black;
  width: 100%;
}


/* styling */

th {
  border-right: 1px dotted red;
}

th {
  height: 50px;
}

td {
  border: 1px solid black;
}

tr {
  border-left: 1px solid black;
}


/* Remove default inline-block of font awesome .fa class */

td i {
  display: unset !important;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<h5>Drag the right border of the th elements and make the cells smaller. All fa-icons but the first have disappeared when you make the cells wider again.</h5>
<table>
  <thead>
    <tr>
      <th>Column</th>
      <th>Column</th>
      <th>Column</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>
        text works normally
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
      <td>
        <i class="fa fa-cog"></i>
        <i class="fa fa-edit"></i>
        <i class="fa fa-trash"></i>
        <i class="fa fa-check"></i>
      </td>
    </tr>
  </tbody>
</table>

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 there a way to eliminate text from a barcode image using JavaScript or TypeScript?

This is my unique html code <div class="pr-2" style="width: 130px"> <div *ngIf="!element.editing" > <span class="ss">{{element.barcode}}</span> </di ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

Experiencing a problem with line breaks while testing a mobile application on an actual device (iPhone using Safari)

I have developed a mobile application with an icon that I manually created - a circle with text and a number inside. When testing it on a PC, everything looks and functions perfectly; however, when viewed on a mobile device, the text breaks to a new line e ...

What is the best way to modify the appearance of a :hover state in the navigation bar?

I'm having trouble changing the shape of the hover effect on my navbar social icons. Currently, it covers more space than I'd like: https://i.sstatic.net/oq25V.jpg What I want is for the hover effect to only appear on the icon itself, not above ...

changing the contents of an array within the current state

My current task involves updating a list of names in the state before sending it as props to another component. // code snippet omitted for brevity this.state = { // other states here playerName: { player1Name: 'Default Player 1 Name ...

Internet Explorer 6 doesn't allow for DOM manipulation of the created combobox in Ajax time

When making an async request on a website, the response is parsed into a select field where the option gets selected once the DOM nodes are ready. This process works perfectly on all browsers except for Internet Explorer 6, which presents some strange beha ...

Mastering jQuery prior to delving into JavaScript skills

Just a heads up – I'm not here to debate whether learning JavaScript should come before jQuery. I already know that jQuery is built on top of JavaScript, so it makes sense to learn JavaScript first. I have a background in HTML and CSS, but now I wa ...

React app (storybook) experiencing loading issues with @font-face

I am struggling to load custom fonts from a local directory. Can someone provide assistance? Below is the code I am currently using: @font-face { font-family: 'My Custom Font'; src: url('./fonts/MyCustomFont.eot'); src: url(&apo ...

Hiding a description on the mobile version of a Blogger website can be achieved by applying CSS

Can anyone assist me with a CSS code problem I'm facing? I tried to hide the blog description using the code below, but it's not working on the mobile version. Any suggestions? .header .description { display : none; } ...

Developing a custom mixin to alert a banner at the top of the webpage

I currently have a feature on my website that triggers a pop-up notification whenever a message is received from another user. The pop-up consists of a div displaying the content of the message along with a close button. After exploring various methods to ...

Identify the ANGLE using JavaScript

I'm experiencing an issue with my WebGL / Three.js game where there is an unhelpful shader program linking error when ANGLE is used for providing WebGL. To address this, I am looking to implement a prominent warning specifically for ANGLE users on the ...

`How to integrate browserify with grunt to optimize jquery-ui`

Whenever I encounter the "Error: Cannot find module './core' from '/var/www/html/psychedharma/public_html/vendor'" I typically avoid using browserify, but it seems that jquery-ui requires it (pun intended.) If anyone could offer som ...

Toggle visibility of column in table using cookies

I was looking to store user preferences for shown/hidden columns in the browser using cookies, so that the table layout wouldn't reset upon page refresh. Fiddle : http://jsfiddle.net/HvA4s/72/ HTML <a href="edit" id=edit>Show/Hide Columns< ...

What is the best way to automate a website that has identical buttons with the same class, but different HTML onlick functions?

One of the buttons reads <button class="btn bid-hotel-btn" type="button" onclick="buyNow(0,false)">Beli Sekarang</button> while the other button is <button class="btn bid-hotel-btn" type="button" onclick="buyNow(1,false)">Beli Sekarang ...

Google Maps API - Custom Label for Map Markers

I am trying to implement a custom map on my website, and everything seems to be working fine except for one issue. The red marker on the map needs to have a label, but I don't want to use an additional image as an icon. Is there a way to add a label ...

Using .change(); in JavaScript code with jQuery does not trigger a function

Here we have a generic code example for a jQuery function: $(document).ready(function() { if (something) { // This does something } else if (something else) { // This does something else } else { // And this does somethin ...

Guide for packaging the JavaScript loaded by the script manager from a CDN in Asp.Net

Currently, I am working on an asp.net application that utilizes a script manager in the master page. My goal is to load all scripts related to the script manager from a CDN, so I have set EnableCDN="true" in the script manager. <asp:ScriptManager runat ...

What techniques can be employed to restrict or define imported data in React through mapping?

Starting my React journey with a single-page application, I am looking to bring in a static collection of personal information like this: { id: '1', link: 'john-doe', name: 'John Doe', title: 'Head of ...

Why does the styling of the inner Span adhere to the style of the outer Span?

How can I adjust the opacity of the color "blue" to 1 in the code snippet below? <!DOCTYPE html> <html> <body> <p>My mom's eyes are <span style="color:blue;font-weight:bold;opacity:0"> <span style="color:blue;fo ...

The default zoom setting for ng-map is overly magnified when paired with the zoom-to-include-markers="true" feature

When using maps, I encountered an issue where having only one marker with the zoom-to-include-markers="true" attribute resulted in the map being overly zoomed in. Regardless of how I adjusted the zoom attribute, the result looked like this: https://i.sstat ...