Troubleshooting: CSS calc function not functioning properly in Firefox

My goal is to dynamically adjust the widths of td elements in my table. This functionality works smoothly in Chrome and Safari, but not in Firefox.

Check out the fiddle here

Here is the HTML structure:

<table border="0" cellspacing="0" cellpadding="0">
    <tr>
        <td>1</td>
        <td>Title</td>
        <td>Interpret</td>
        <td>Album</td>
        <td>Year</td>
        <td>YouTube</td>
    </tr>
</table>

And this is the CSS I am using:

table{
    table-layout:fixed;
    width: 100%;
    border-collapse: collapse;
}
td{
    border:1px solid red;
}
td:first-child{
  width: calc(100% / 6 * 0.5);
}
td:last-child{
  width: calc(100% / 6 * 2);
}

Interestingly, hard coding pixel values like calc(690px / 6 * 2) instead of using 100% seems to fix the issue in Firefox.

Answer №1

Get rid of the following CSS line:

table {
    // table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
}

The property table-layout: fixed allows you to set your own widths for a table. It's frustrating that Firefox is not cooperating with this particular rule.

If you need more information, check out: using calc() with tables

Answer №2

To make this method effective, I have come to realize that in order to simulate a fixed cell width, the table-layout should be switched from fixed to auto, along with establishing a default width for all td's.

For a dynamic approach, the table width is divided by the number of columns (in this case as a percentage) -- resulting in 100 / 6 = 16.66666....

This value is then incorporated into the calc() function for both :first-child and :last-child, replacing 100% with 16.6666% while retaining the current modifiers (0.5 and 2, respectively).

CSS

table{
    table-layout:auto;
    width: 100%;
    border-collapse: collapse;
}
td{

    border:1px solid red;
    width: 16.6666%;
}
td:first-child{
  width: calc(16.6666% * 0.5);
}
td:last-child{
  width: calc(16.6666% * 2);
}

Check out this Example Fiddle

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

What's the issue with my jQuery AJAX script?

I am experiencing an issue with my ajax pages using jQuery to retrieve content. Only one page seems to be working properly, even though I have multiple pages set up. How can I resolve this problem? $(document).ready(function() { $('.lazy_content& ...

What is the best way to ensure that my background image remains fully covering the screen even while scrolling or resizing

Struggling with implementing parallax scrolling through multiple images. Encountering two main issues: 1) Tiling occurs with repeated images or incomplete display, and 2) Inconsistent resizing on different screen sizes, particularly mobile phones. Any s ...

Tips for customizing the calendar icon on a date input in Firefox versions greater than 108

Prior to version 109, Firefox allowed for the selection of the date picker's icon similar to Chromium: input[type="date"]::-webkit-calendar-picker-indicator { display: none; /* Hides the icon in Chrome and Firefox < v109 */ } This func ...

Taking an item out of a List causes a disruption in the order of the remaining items

I'm currently working on a Blazor project where I have an HTML table that populates by looping over a list. Here is the relevant code snippet: @foreach (var line in lines) {@{ var linenumber = lines.IndexOf(line)} <td> ...

MultiArray authentication system

I am currently working on a multi-array login system, but I am facing an issue where only the first account is functioning properly. The other two accounts are displaying incorrect password or username errors. Account 1 corresponds to the name, Account 2 ...

How to implement responsive CSS in Laravel 4

It has come to my attention that in Laravel 4, you can load CSS and scripts using the following method: {{ HTML::style('css/style.css'); }} Which will result in: <link media="all" type="text/css" rel="stylesheet" href="http://localhost/cupc ...

Arranging expandable divs horizontally

Looking for a way to align these blocks so they can expand while remaining in line, I'm struggling with maintaining their individual spaces. The layout I have in mind is as follows: In this setup, box 2 and 3 should automatically adjust to fill the a ...

EffortlessDrop.js and anchors

Currently using EasyDropDown.js to style a select element, which creates a modern dropdown menu using jQuery. I'm curious if it's possible to include a hyperlink in one of the select options. Here's an example of what I'm trying to ach ...

Employing state management in React to toggle the sidebar

A working example of a sidebar that can be toggled to open/close using CSS, HTML and JavaScript is available. Link to the Example The goal is to convert this example to React by utilizing states instead of adding/removing CSS classes. To ensure the side ...

What is the best way to generate a search link after a user has chosen their search criteria on a webpage?

In my search.html file, I have set up a form where users can input their search criteria and click the search button to find information within a database of 1000 records. The HTML part is complete, but I am unsure how to create the action link for the for ...

What are the steps to set up the ionic framework on my Windows 7 system?

I am looking to set up the Ionic framework on my Windows system. However, I encountered an error while trying to install it. The warning 1909 appeared stating that it could not create a shortcut for node.js command prompt.ink. It asked me to verify if th ...

Add a Page to Your Domain Name using the Text Input Box

I'm looking to create an input field that allows users to enter a text string, which will be added to a domain name when submitted, redirecting the user to a specific page. Here's how the process works: The user enters 'foo' into the ...

What is the process for ensuring that the "ng-multiselect-dropdown" is a mandatory field within Angular 7?

Is there a way to require the ng-multiselect-dropdown field to have at least one selected item? <ng-multiselect-dropdown [placeholder]="'Select countries'" [data]="countries" [(ngModel)]="countriesSelectedItems" [settings]="co ...

At times, receiving text is possible, but occasionally the message "Element cannot be located with provided selector" may appear

When using var n = I.Find(("#CSS_path"); to locate an element and click on it, I encountered a problem when attempting to compare the text inside. Initially, I tried using var nt = n.Element.Text; and string name = n.Element.ToString(); to retrieve the tex ...

Creating an HTML table on-the-fly leads to the opening of a fresh new webpage

Has anyone encountered this issue before? I have a math table coding function, which runs when a button is clicked. However, when I click the button, the table appears on a new page instead of on the same page. <!doctype html> <html> <h ...

Tips for utilizing multiple CSS styles in JavaScript

My goal is to apply multiple CSS styles to a button with the id of name_button. Below is the JavaScript code I have written: var name_button = document.getElementById('name_button'); name_button.style.display = 'block'; name_button.st ...

Are Margins in CSS Really a Negative Aspect?

After testing my website on various browsers, I've encountered issues with margins when elements are floated. Surprisingly, Firefox displays the site correctly, but IE7 and some Linux browsers mess up the margins completely. If you're curious to ...

What are the reasons why Bootstrap icons are not functioning properly in ReactJS?

I am facing an issue with bootstrap icons not working in ReactJS. Click here to view my buttons This is the code for my post items: import React from 'react'; const PostListItem = () => { return ( <li className="app-list ...

Is it possible to include jQuery's selectors contain and closest within my CSS selector?

I created a script to hide specific table rows as follows: $('.ms-formtable nobr:contains("Question")').closest('tr').hide(); However, I'm unsure if there is a way to achieve the same result using only CSS. Can anyone provide adv ...

What is the best way to display an alert box through AJAX technology?

My code snippet is as follows: <script> function updateQty(quantity) { $.ajax({ alert(quantity); }) } </script> Here is the corresponding HTML markup: <form name="quantityForm"> <select name="quantity" id="quantity" onChan ...