Disappearance of CSS borders when using jQuery scroll function

After implementing a fixed table header for an HTML table on my website, I encountered a minor issue. When scrolling down, the table header remains at the top as intended, but the CSS styling for borders within each <th> element disappears. The font weight and text alignment remain unchanged while scrolling. Here is the code snippet:

HTML:

<div class="tableFixHead">
    <table id="Downloads" class="sort">
        <thead>
            <tr>
                <th>Application</th>
                <th>Release Version</th>
                <th>Application Type</th>
                <th>Download File Type</th>
                <th>Download File Size</th>
                <th>Download Button</th>
                <th>Download Progress</th>
                <th>Download Message</th>
                <th>Save File</th>
            </tr>
        </thead>
        <tbody>
            <!--Rows for the body of the table-->
        </tbody>
    </table>
</div>

CSS:

table {
    margin: auto;
    border-collapse: collapse;
}

.tableFixHead {
   overflow-y: auto;
   height: 600px;
}

.tableFixHead thead th {
    background-color: orange;
    font-weight: 600;
    text-align: center;
    border: 3px solid #3F2860;
 }

jQuery:

var $th = $('.tableFixHead').find('thead th')
$('.tableFixHead').on('scroll', function() {
   $th.css('transform', 'translateY('+ this.scrollTop +'px)');
});

In an attempt to restore the borders, I adjusted the css() method in jQuery with no success:

$th.css({'font-weight':'600', 'text-align':'center', 'border':'3px solid #3F2860', 'transform':'translateY('+ this.scrollTop + 'px)'});

According to the documentation, the css() method should not overwrite existing styles but rather append to them. Therefore, my suspicion is not on the jQuery script. You can view the table on this page: , located about one-third down the page. Any assistance would be greatly appreciated!

Answer №1

The reason for this issue is the use of border-collapse: collapse; on the table element, which removes the borders. To fix this, you can change it to border-collapse: separate; and then add the desired border styles to your table. Upon closer inspection, you'll notice that the borders you tried to add were not appearing as expected (perhaps set them to 13px). Instead, there will be a large gap with the actual table content scrolling behind it.

table{
  border-collapse: separate;
}

.tableFixHead thead th, .tableFixHead td{
  border: 3px solid #3F2860;
}

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

Determine the total hours and minutes elapsed between two specific dates and times

Looking for some assistance here. I have a form where users need to input a start time and end time of an incident. After entering this information, they would manually calculate the duration between the two date times. I am attempting to streamline this p ...

How can I show the remaining paragraph text upon clicking a button in a responsive manner using CSS and JavaScript?

I want to add a nice animation effect to the height of my text when a button is clicked. I've managed to achieve this by setting a height: 30px with overflow: hidden initially, and then toggling a class with height: 300px. However, I'm facing an ...

Updating the Scale of the Cursor Circle on my Portfolio Site

I attempted to find tutorials on creating a unique circle cursor that can hide the regular mouse cursor as well. After implementing it with a difference blend mode, I encountered an issue where I wanted the scale to change when hovering over a link. The ...

When working with ASP.NET MVC 3, be aware that the ContentResult may not accept a class that inherits from

After my previous question regarding finding nearby entities with Bing Maps REST control, I have made some modifications. Within the for loop of the function DisplayResults(response), the following code has been added: var loc = new Array(); loc[0 ...

When using jQuery, the value of an input type text field remains constant despite any alerts

My issue involves an input text used to check if the corrected values are being displayed in an alert. However, when I modify a value in the form and check if the updated value appears in the alert box, it still shows the old value. Below is the relevant ...

Ways to conceal the contents of an HTML element

I recently applied a background image to my "a" tag, but now I'm looking to hide only the HTML content within the tag. It's important that the background image and href address remain visible. Any suggestions on how to achieve this? Thank you in ...

How can we stop mobile email applications from automatically converting emails into a "mobile-friendly" layout without permission?

My email design is optimized to look great on mobile, web, and desktop mail clients. However, I'm facing a challenge with some mobile clients like Gmail on Android automatically reformatting the email to make it more mobile-friendly. This leads to a m ...

Transferring Specific Information to Individual Fancybox Instances

I'm currently in the process of integrating Fancybox 3 into my application. My goal is to create a custom button that performs specific functions for each instance, requiring additional data such as photoId and settingsId. To illustrate: HTML: Withi ...

Incorporating JavaScript/jQuery values into C# backend with ASP.NET

Despite attempting all possible methods, I am unable to pass the screen.width value from a JS script on an aspx page to C# in the code behind. Even though the screen.width is correctly assigned, it never gets passed to my hidden field value. <asp:Conte ...

What is the method for overlaying text and a hyperlink onto an image in Bootstrap?

After spending a considerable amount of time tweaking positions, z-index values, and other properties in an attempt to make Bootstrap work seamlessly on top of an image, I have arrived at what I believe is the most efficient code snippet. img { disp ...

Stop the text from wrapping to the full width of its parent when it overflows onto the following line

When I shrink the width in responsive design, the text overflows to the next line and the text wrapper expands to fit the parent container. Is there a way to prevent this behavior so that it looks like the red container? I could add padding to the contain ...

Alignment of card images

Is there a way to keep the images in my cards fixed at the top of the card body? I've tried using bottom: 0 but it's not working as expected. The card body has a fixed height and is fixed to the bottom, which is functioning correctly. However, si ...

What is the process for adding a custom header when making an ajax call in a datatable?

Currently, I am utilizing datatables and need to include a custom header for specific server-side requirements. Can anyone provide guidance on how to send a custom header when navigating to the next or previous pages using jQuery datatables? Additional ...

ways to disrupt a timeout

I am attempting to incorporate a functionality similar to this example: https://www.w3schools.com/jsref/met_win_cleartimeout.asp On my personal website: If you enter certain characters in the input field, select one of them, and then pause for 5 seconds, ...

Mastering the Art of Scrolling

Can someone please tell me the name of this specific scrolling technique? I am interested in using something similar for my project. Check out this example site ...

Implement JQuery UI Accordion to enhance navigation on mobile devices

I am implementing the JQuery UI Accordion to expand content on a website. Below is the basic markup structure: <div class="accordion"> <h2>Heading</h2> <div>Content</div> <h2>Heading</h2> <div& ...

Ensure that autocorrect is set to suggest the nearest possible quantity form in WordPress

I'm currently in the process of creating a webshop using WooCommerce. Our quantity system is a bit unique, as we are using WooCommerce advanced quantity, which means that quantities increase by 0.72 increments (e.g. 0.72, 1.44, 2.16 etc). The +/- butt ...

The ng-model in Angular is unable to capture the initial input value on load

I am currently using a window onload script to obtain longitude and latitude data and pass them to hidden input values. $(function() { window.onload = getLocation; var geo = navigator.geolocation; function getLocation() { if (geo) { geo ...

A guide to setting up a queue for ajax requests with jQuery

How can I create an efficient Ajax request queue using jQuery? My goal is to: Allow users to trigger multiple Ajax requests in a web page, which should be queued and processed sequentially. Update the web page based on server responses. Implement e ...

Turn the image inside the div with the nth-child selector into a clickable link

I'm currently facing a challenge on my Squarespace website where I need to add individual links to various images using jQuery. The issue is that these images do not have a shared class, and unfortunately, I am limited to adding custom CSS or JavaScri ...