The table width is malfunctioning on Firefox when viewed in HTML

I have been puzzled by the fact that I am unable to adjust the width of the table th in Firefox browser to the smallest value. However, in Chrome browser, this functionality works perfectly. I simply want to divide the values of my td into three rows as shown in the image below but specifically in Firefox.

Here is how it appears in Chrome:

https://i.sstatic.net/Q4hxJ.png

And here is how it looks in Firefox where it doesn't work as intended:

https://i.sstatic.net/qKbtC.png

Below is the entire HTML code snippet for reference:

<section class="users-list-wrapper">

  <div class="users-list-table">
    <div class="card">
      <div class="card-content">
        <div class="card-body">

          <div class="table-responsive">

            <table class="table" name="table" id="table">
              <thead>
                <tr>
                  <th colspan="9">
                    <div class="titles">
                      <h3>This is Header title <br style="line-height: 20%;">
                        <span class="header2"> SubHeader title</span>
                    </div>
                  </th>
                </tr>
                <tr>
                  <th colspan="4" style="text-align: left;">
                    <span class="municipality">Header</span>
                  </th>
                </tr>
                <tr class="heads">
                  <th class="heads">No</th>
                  <th width="5%" class="heads">ID Number</th>
                  <th class="heads">Name</th>
                  <th width="2%" class="heads">Country</th>
                  <th class="heads">Data total</th>
                </tr>
              </thead>
              <tbody class="report-content">
                <tr>
                  <td></td>
                  <td>1235</td>
                  <td>Jason</td>
                  <td width="10px;">PH-COVID-160203000-00010165</td>
                  <td class="lenss"></td>
                </tr>
                <tr>
                  <td></td>
                  <td>1235</td>
                  <td>Jason</td>
                  <td>United States</td>
                  <td class="lenss"></td>
                </tr>

              </tbody>
            </table>

          </div>
        </div>
      </div>
    </div>
</section>

Answer №1

Check out the wbr element - it can be implemented dynamically

[...document.querySelectorAll("tbody tr td")].forEach(td => {
  const text = td.textContent;
  if (text.length > 20 && text.indexOf("-") != -1) 
    td.innerHTML = text.replace(/-/g, "<wbr/>-")
})

To target long content with regex and split accordingly:

[...document.querySelectorAll("tbody tr td")].forEach(td => {
  const text = td.textContent;
  if (text.length > 20 && text.indexOf(" ") == -1 && text.indexOf("-") != -1) {
    td.innerHTML = text.replace(/-/g, "<wbr/>-")
  } else if (text.length >= 10) { 
    td.innerHTML = text.replace(/(\w+)/, function(match, word, index) {
      return word.length<10 ? word : word.split(/(.{10})/).filter(O => O).join("<wbr/>-")
    })
  }
})

View the results in different browsers:

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 method of inserting a JSON dates object to deactivate specific days

I am currently utilizing a date picker component that can be found at the following link: While attempting to use the disabledDays section below, I have encountered an issue where I am unable to apply all three options. The blockedDatesData option works o ...

Baffling Visibility Issue: iframe's Transparency Lost in Chrome and IE, Only Visible in Firefox

I have encountered a puzzling issue: http://jsfiddle.net/akosk/t2KvE/8/ HTML <div id='base'> <iframe id="myFrame" src="about:blank" frameborder="0" allowTransparency="true"></iframe> </div> <script id="conte ...

Retrieving all options from a dropdown list in HTML using ASP.net C#

I am currently working with a select list that looks like this: <select name="Section" id="Section" size="5"> <option>Section1</option> <option>Section2</option> <option>Section3</option> <option>Section4< ...

Please input a number that falls within a specified range

I need help with two text inputs that are connected v-model to a ref object. I also have two other refs, minimum (100) and maximum(1000). My goal is to allow users to input values within the range of the minimum and maximum values provided. If the value en ...

Utilizing Shopify API to seamlessly add items to cart without any redirection for a smoother shopping experience

Looking for a solution to submit an add to cart POST request without any redirection at all? I have tried changing return_to to "back" but that still reloads the page, which is not ideal. My goal is to smoothly add the item to the cart and notify the cli ...

Ensure that ExpressJS response includes asynchronous try/catch handling for any errors thrown

Currently working with ExpressJS version 4.16.0, NodeJS version 10.15.0, along with KnexJS/Bookshelf, and encountering issues with error handling. While errors are successfully caught within my application, the problem arises when trying to retrieve the e ...

Using the HTML video tag to apply different background colors based on the individual machines being

My web application includes a video that is set to play against the same background color as the webpage. However, I am experiencing an issue where the video background appears differently on various machines using the same browser. What I would like to ac ...

Is there a way to change the color of a number's font based on whether it is preceded by a "+" or "-" sign?

I am currently working on a stocks widget and I have a specific requirement. Whenever there is a change in value in the Change or Changeinpercent columns, I need to dynamically set the font color to red for a decrease (-) or green for an increase (+). Her ...

Leveraging functions with Ng-Repeat

I am currently dealing with two different arrays of objects. The first array contains a list of permissions groups, while the second array consists of user groups. My main goal is to compare the Group Owner (which is represented by ID 70) with the list of ...

Updating the parent's reference from a child component in Vue 3

In one of my child components, I have a component named Navbar that includes an option for logging out. <a @click="(event) => {event.preventDefault();}"> Logout </a> This Navbar component has been imported into my parent compon ...

Issue when sending PHP Papa Parse object through AJAX

I am currently working on extracting a CSV local file in PHP using AJAX and have found success with Papa Parse. However, I am facing difficulties passing the results with AJAX. Despite trying various methods such as JSON.stringify, passing only the first f ...

Tips for avoiding incorrect data entry in input fields

Is there a way to prevent the input type number from having an undefined value? For instance, like shown in the image below: https://i.sstatic.net/z1pZH.png Any ideas on how to restrict the input to only accept plus or minus values? ...

Customize Appearance: Overlay Images with Display Properties

I have created a unique slideshow that overlays multiple images using JavaScript to change their opacity and attributes. You can view the slideshow here: Upon inspection (using firebug), I noticed an issue with how the images are displayed. When the displ ...

Pass a selected object to a dropdown/select change event using AngularJS

Plunkr : http://plnkr.co/edit/BRQ3I4hFTlgKq4Shz19v?p=preview I'm attempting to pass the selected item from a dropdown to a function within my controller. Unfortunately, I keep receiving it as undefined. HTML : <!DOCTYPE html> <html> ...

Dropdown selection values were not set appropriately

I've been encountering an issue with setting the selected value in a drop-down list using the code below. The values are being split from a comma-separated string, but it's not functioning as intended. When I use string='text1,text2,text3,t ...

Ways to change the background image when hovering in a React component

I'm having trouble trying to scale my background image by 1.5 when the user's mouse enters. Here is the code I have so far: import React from 'react'; import Slider from './index'; import horizontalCss from './css/hori ...

Tips on adding CSS to a React component

I've successfully converted an HTML file into a component designed to resemble a 7-segment LED display. I have imported the necessary CSS styles from the index.css file, but I am unsure how to properly apply these styles within the component. My atte ...

Radio button selection with table layout

I am designing a quiz template with radio buttons. However, I would like them to be stacked vertically instead of side by side. Why doesn't the <br/> tag work? I'm having trouble understanding it. Can someone assist me? Here is my code: ...

How can I adjust the appearance of an HTML tag within an Angular component?

I have created an Angular component with the following definition: import { Component, Input, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'rdc-dynamic-icon-button', templateUrl: './dynamic-icon-button. ...

CSS: The deleted style refuses to disappear

Despite removing CSS code from my Rails application, after restarting the server and refreshing the page, I still see that the code is in effect. Even when inspecting the elements using Chrome, the code remains visible. @media screen and (min-width: 961px ...