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

What is the best way to iterate through my array and display each value within my button element?

I have a challenge where I'm trying to iterate over an array named topics. This array contains the names of various people. Within my loop, my goal is to extract each name and insert it into a button as text. When I use console.log within my loop, I ...

"Interactive jQuery feature allows users to edit table content live with the ability to update and delete data via

I am working on implementing live editing, updating, and deleting functionality in a table using jQuery. However, I have encountered two problems: When clicking the pen icon from order #3 to #1, it requires 3 clicks, but when clicking from order #1 to ...

I am looking to bring in just the tables from a different html/php page

I am currently working on a webpage that includes a php library, header, and other elements. I only need to import specific tables and information from this page onto another screen display, with the tables arranged side by side instead of vertically. My ...

The scrollbar remains visible on mobile devices

I'm attempting to remove the scrollbar from all elements in my Vue + Vite application. I do not want to disable scrolling, just hide the scrollbar itself. To achieve this, I have employed the following code snippet. *::-webkit-scrollbar { display: ...

What is the best way to incorporate a button in my code that automatically triggers changes at regular intervals?

Is there a way to automatically change the color of my working traffic light in JavaScript on a timed basis, rather than relying solely on button clicks? Here is the current code I am using: <!DOCTYPE html> <html> <head> <style> # ...

What steps can I take to eliminate the initial delay when it is first invoked?

My function is being called every 10 minutes like this: var interval = self.setInterval(my_func, 600000); function my_func(){ $.ajax({ url: 'xxxxxxxx', success: function(response) { var data= JSON.parse(response); dis ...

Utilize MaterialUI's stepper component to jazz up your design with

Is there a way to customize the color of a material ui Stepper? By default, the material UI stepper's icons use the primary color for both "active" and "completed" steps. class HorizontalLinearStepper extends React.Component { state = { activeS ...

What is the best way to ensure that the viewBox of an SVG perfectly matches the size of the image it overlays?

I am looking to create a simple GUI using the Python NiceGUI Library. In my design, I have divided the interface into two columns using the grid element, with cards containing checkboxes on the left for overlays. On the right side, I have inserted an imag ...

What is preventing HTML from triggering JavaScript when loaded inside a <div> with a script?

I'm working on creating a collapsible menu that I can easily customize on any page without the use of iframes. As someone new to web design, I have knowledge of CSS and HTML but I am currently learning JavaScript with limited experience in jQuery or A ...

Using jQuery to append content with a variable as the source

Recently delving into jQuery and encountering an issue with getting my variable inside src when using append. Either it's not functional at all, or just displaying the variable name in string form in the console. Here is the code causing trouble: va ...

The error message encountered is related to a problem with the e.slice function within the Kendo UI

Everything was running smoothly until serverGrouping feature was activated and I tried to group some data by dragging and dropping a column. An error message appeared on the JavaScript console: e.slice is not a function. I suspect that there might be an ...

What is the best way to use a button to hide specific divs upon clicking?

Is there a way to use a button onclick event to hide specific divs within a parent div? I've tried using .toggleClass('.AddCSSClassHere') but I'm not sure how to apply it to multiple divs. The jQuery snippet provided only allows me to h ...

PHP Ajax Tutorial - Sending an HTTP request and displaying the retrieved data

I currently have two files. One is an API called "sqltest.php" When I access it on my server, I receive the following output: ["39","blah"] My client.php file contains jQuery ajax code to retrieve this data and display it correctly in the web browser. ...

Is there a way to use AJAX for transferring a value?

I am looking to transmit a value to a php-script (servo.php) that will then write the received data in a file (/dev/servoblaster). The script section of my HTML file (index.html): <script> function tiltt() { var tilt = document.getElementById("tilt ...

Animate a div once the parent section becomes visible while scrolling

I previously had this function working, but it seems that I have somehow messed it up in the process. My current setup includes a scroll hijack feature that navigates users to a new section or card each time they scroll. The script adds a visible class w ...

The NodeJS expressJs Server is unable to receive JSON data

Here is how my ajax request is structured: $.ajax({ url: baseURL, type: 'POST', data: JSON.stringify(sendData), contentType: 'application/json; charset=utf-8', dataType: 'json', async: false, succe ...

Converting HTML and CSS to PDF in Java using iText

I've been working on converting HTML to PDF. Initially, I transformed my HTML code into XHTML using the resources provided in this link: After successfully displaying the generated XHTML code in a browser by creating an HTML file for testing purposes ...

Tips for displaying AJAX response on a new webpage

I am currently working on a mobile app using Phonegap and Intel XDK. My goal is to display an AJAX response on a new HTML page. After doing some research online, I came across the solution of using window.open();. However, this method did not work for me ...

The scrollable dialogue disrupts the background's ability to flex and grow

My page layout is pretty simple: <main> <header>Header</header> <section>Content</section> <footer>Footer</footer> </main> <dialog>Dialog</dialog> In terms of CSS, here's how it ...

What is the process for adjusting the color of the browser tab?

My chat application is running smoothly, but a client has requested the ability to highlight or make the browser tab blink when they receive a visitor call. This will help them respond promptly to incoming inquiries. Does anyone know how to implement thi ...