Error copying cell width attribute when using border collapse

Currently, I am attempting to duplicate a table header by copying the tr HTML and then replicating the th widths. Unfortunately, this method is unsuccessful as the widths are displayed as (width minus W) pixels when border: 'Wpx' and border-collapse: 'collapse'. If border-collapse is not set, the widths appear correctly.

The code used for this task is quite simple:

var arr = [];

// Copy html from source to destination tr
$abc.html($def.html());

// Now replicate the widths of the table header cells 
$def.children().each(function()  {arr.push($(this).css("width"));});
$abc.children().each(function(index) {$(this).css("width", arr[index]);});

To see the problem in action, take a look at this Fiddle: http://jsfiddle.net/marvmartian/9z24j7vz/4/

An alternative solution to this issue (demonstrated in the Fiddle but currently commented out) involves checking the final table sizes. If they are not equal, a workaround is applied by increasing the widths before setting them.

This strange behavior might initially seem like a bug, especially while using Chrome. But apparently, it is intentional. What am I overlooking here?

Answer №1

Here is a solution:

table.pvtTable tr th {
    background-color: #e6EEEE;
    border: 6px solid black;
    padding: 5px;
    box-sizing:border-box;
}

In Chrome, cell widths are calculated differently due to border-collapse behavior (I assume). By including borders in the width calculation in your CSS, you can ensure consistent results. It's uncertain which browser (Firefox or Chrome) is correct in this case. :)

Check out the fiddle here: http://jsfiddle.net/9z24j7vz/5/

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

Generate a new tree structure using the identifiers of list items within an unorganized list

Attempting to convert the id's of li's in a nested unordered list into valid JSON. For example, consider the following list. To be clear, the goal is not to create the UL list itself, but rather the JSON from the li id's <ul class="lis ...

What is the best way to ensure the active tab remains visible?

I am using the bs-admin-bcore Bootstrap theme and I am looking to enhance the dynamic functionality of the menu in the "menu.php" file. Here is an example of the current code: <ul id="menu" class="collapse"> <li class="panel"> < ...

Utilizing objects from a JSON file within an HTML document

I'm currently in the process of creating a comprehensive to-do list, and I want to establish a JSON file that will link all the items on the list together. Despite my efforts, I find myself uncertain about the exact steps I need to take and the speci ...

How can I position text in the top right corner of a v-card's v-img component in Vuetify.js?

I am using Vuetify.js and I am trying to show a single word on the right side of an image within a v-card: <v-card> <v-img src="https://cdn.vuetifyjs.com/images/cards/desert.jpg" aspect-ratio="2.75"> <span class= ...

How to hide offcanvas navigation bar with one click in Bootstrap 5

There was an issue with a Bootstrap 5 project where the offcanvas menu would remain open after clicking on an anchor link. Is there a way to automatically close the offcanvas menu after clicking on an anchor link? <nav class="navbar fixed-top py ...

What is the reasoning behind utilizing the "&" selector in CSS?

.navigation { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: translation: all ease 0.25s; &.expand { transform: translateX(0); } } JavaScript file: $(document).ready(func ...

Steps to resolve the error message 'npm ERR! Cannot read property 'startsWith' of null':

As I embark on creating my very first react-native app, I encountered a stumbling block while trying to set up the react-native command line interface following the instructions provided here. Every attempt I make to initialize the react-native command lin ...

Navigating on Blogger can be a tricky task when it comes to searching and

I recently added a Table to my blogger post, along with an input form for readers to easily search data. After finding the code on W3Schools (link here), I implemented it successfully. However, I am looking to make some improvements. Here is my question: ...

The text next to images is being clipped (is it CSS?)

Encountering a problem with CSS on my Wordpress websites. Using WP's editor to float images to the right or left of text, I noticed an issue when viewed on mobile: https://i.sstatic.net/gVFRq.jpg The text gets cut off. How can I ensure that no tex ...

Troubleshooting the compatibility issue between Gravityforms and Jquery File Upload

I want to integrate the JQuery File Upload plugin with Gravity Forms in Wordpress. I've set up a form with a file upload input where Gravity Forms has assigned the field id as input_1_33. This id is being used for the file upload jQuery plugin. jQuer ...

Navigating rows in a Kendo Grid using buttons (Starting, Previous, Next, Ending)

Looking for help with navigating rows on a Kendo-Grid. I have four Buttons - First, Previous, Next, and Last. The goal is to highlight the selected record on the grid when a button is clicked. However, I'm struggling with making the Kendo-Grid highlig ...

Troubleshooting MVC3 @Ajax.ActionLink: Unexpected Page Display Instead of Target UpdateId Replacement

My current project is built with VS2010/.net4/MVC3 (MVC4 encounters the same issue) I am attempting to invoke an AJAX function in my project @Ajax.ActionLink("Display ALL Cbms results", "All" , "Cbms", new AjaxOptions() { HttpMethod = "GET", Upda ...

Is there a way to adjust the placement of text in an HTML document?

Just starting out with web development and created some HTML code: <html> <body> {errors} <p>Input your numbers:</p> <form method="post" action="."> <p><inpu ...

Photo not completing the table

Hey there, I'm currently working on creating a table to showcase some products but I am struggling with ensuring that the images display at the correct size. Any assistance on this matter would be greatly appreciated. #tbldesktops { width: 100%; ...

Bug found in React Native when navigating between screens causing the screen size to shrink

Check out the image below. https://i.stack.imgur.com/t04Vv.png Issue: Whenever I switch to a new scene, the previous screen appears to shrink or move upwards. This behavior is not consistent with the usual user experience seen on Apple apps - any thought ...

Using AJAX to communicate with a MySQL database and create a countdown timer using JavaScript

I have been trying to display data from a database using Ajax and incorporate countdown timers with times also fetched from the same database. It has been a struggle for me for almost 24 hours now. You can check out the main code here where you will notic ...

Manually reloading the page causes issues with AngularJS routing functionality

I've been attempting to manually reload the page from my browser, but unfortunately it's not working and is displaying an error message: Cannot GET /rate/4 This is what my route setup looks like in Angular: angular.module('routing&ap ...

Can you tell me how to achieve the functionality of the ".get" statement in JavaScript that is present in python-firebase?

After writing Python code that retrieves the entire JSON database, I attempted to achieve the same functionality in JavaScript without success. Despite its apparent straightforwardness, I have yet to discover a viable solution. var firebase = require(&apo ...

Framer motion layout animation fails to account for page scrolling during transitions in NextJs routes

Currently, I am working on a fascinating NextJS project that showcases a series of interactive blocks. As the user navigates through the app, these blocks dynamically adjust their size and position on the screen. To achieve this effect, I'm leveragin ...

Finding the appropriate method to access a template variable reference in a designated row of an Angular Material table (Angular 7)

Currently, I am working on implementing a more intricate version of a behavior inspired by Angular Material's tutorials. In my simplified example, an Angular Material table is populated with data from a string array. The first column contains input fi ...