CSS - Keeping table data within fixed table header bounds for Overflow-X

When it comes to the Table Fixed Header, my main concern is having all text properly aligned under the fixed header without any misalignment issues. The setup works perfectly for everything within the second table as it stays within 98% of the width.

The problem arises with the first table where I have a TD tag that utilizes white-space:nowrap to keep the content on one line. However, when an overflow-x occurs, this causes the fixed header to become misaligned. I am looking for a solution to ensure that the fixed header matches the rest of the table header and remains properly aligned.

The key challenge is making sure that the fixed header does not get jumbled up when Overflow-X: Auto happens and horizontal scrolling is required. It's important to note that adjusting your viewpoint may be necessary to observe this issue.

I suspect that the solution lies in tweaking the CSS or JQUERY code, but I'm struggling to pinpoint the exact adjustment needed...

If you want to explore the issue further, check out the JSFIDDLE link here: https://jsfiddle.net/rbla/1Ljuycbe/61/

.up:hover {
    cursor:pointer;
}

.tooltip2 {
    position: relative;
    display: inline-block;
    border-bottom: 3px dotted black; /* If you want dots under the hoverable text */
    text-decoration: none; 
    color: #00F;
}

img.cadre {
    border: 3px solid #D2D1D1; 
    border-radius: 4px; 
    width: 125px;
    height: 125px;
}

.tooltip2 .tooltiptext2 { 
    visibility: hidden;
    width: 130px;
    background-color: #fff;
    color: #fff;
    text-align: center;
    padding: 5px 5px;
    border-radius: 6px;
    margin-left: 7px;
    position: absolute;
    z-index: 0;
}

.tooltip2:hover .tooltiptext2 {
    visibility: visible;
    cursor:pointer;
 }

.tooltip2 .tooltiptext2 { 
    top: -5px;
    left: 105%; 
 }

 /* Left Arrow */
.tooltip2 .tooltiptext2::after {
     content: " ";
     position: absolute;
     top: 15px;
     right: 100%; /* To the left of the tooltip */
     margin-top: -5px;
     border-width: 5px;
     border-style: solid;
     border-color: transparent white transparent transparent;
 }

  table.blue.fixed {
     z-index: 99;
 }

Answer №1

Finding a solution to your specific issue is quite simple; however, there are numerous ways in which your code could be enhanced. For example, instead of duplicating the entire table element and deleting the tbody, there are other approaches that could be explored. Nevertheless, these suggestions may fall outside the scope of your current question.

To address the problem, you can simply include the following CSS snippets:

.blue.fixed {
  width:100%;
  table-layout:fixed;
}

Check out this JSFiddle link for reference!

Answer №2

$t_fixed.css("width",$this.outerWidth()+"px");
$this.parent().on( 'scroll', function(){
  $t_fixed.css("left",(($this.parent().scrollLeft())*-1)+"px");
});
$( window ).resize(function() {
    $t_fixed.css("width",$this.outerWidth()+"px");
});

To ensure this code works correctly, there are three key adjustments that need to be made:

1) The width of the table must match the original table's width. The first line in the code snippet addresses column positioning.

2) Moving the cloned header row along with the scrolling is necessary to maintain alignment as you scroll through the table.

3) Implementing ".resize" will adjust the table accordingly when the viewport is resized.

Here's a fiddle link for reference.

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

Creating an array of items in an HTML template to generate a PDF using Node.js

In my current project, I am utilizing html-pdf for creating PDFs. I have successfully generated all the necessary details in the PDF, however, I am facing an issue with creating a list of items from an array in HTML, which is required for the PDF convers ...

Add a Font Awesome 5 icon to serve as the background of a Bootstrap 4 card

How can I utilize a Font Awesome 5 icon as the background image for a card using Bootstrap-4? After trying numerous solutions found online, I am still unable to get it to work. My environment consists of Angular2 (v8) in conjunction with Bootstrap 4. ...

Displaying only the radio button without any additional elements, the Ionic 2 radio button (<ion-radio>) offers a

Looking for some guidance on implementing a list with radio buttons using the ion-list and ion-radio directives. The code provided should be clear, but please feel free to ask for more details if needed. I'm still new to Ionic and may be making some ...

Concealing external scripts on specific webpages

In my HTML template, I have integrated a third-party JavaScript code that provides a chat option. This script is included in my header.html so that it appears on all pages. However, I do not want this chat option to display on the login page. I want it to ...

The screen should smoothly slide upwards when the keyboard pops up, ensuring the footer remains und

Hello! I am currently in the process of developing a mobile app using HTML, CSS, Bootstrap, and JavaScript. I have encountered a slight issue where the keyboard does not automatically pop up and move the screen up when the user taps on the textbox in the f ...

Utilizing JavaScript to eliminate objects from a collection and showcase a refreshed arrangement

On a simple webpage using bootstrap and js/jquery, data is fetched via ajax to create entries displayed to the viewer. The process involves: - making a request - parsing XML to create an array of objects with all the data - sorting by one property - cr ...

Increasing and decreasing the display of content using JQuery based on height rather than character count

I'm attempting to create a show more/show less link with a set height of 200px that, when clicked, will reveal the rest of the content. Anything exceeding 200px will be hidden, and there will be a "show more" link to display the remaining text. I&apos ...

Displaying a large image within a small div using Bootstrap 4

I have a specific image with dimensions of 244px by 751px, and I am trying to place it inside a div container that is 132px by 132px. I want the image to maintain its aspect ratio without being stretched. Despite using the img-fluid class, the image does n ...

Put the code inside a function. I'm new to this

My goal is to encapsulate this code: if($(window).width() > 980) { $(window).on("scroll", function() { if($(window).scrollTop() > 20) { //add black background $(".x-navbar").addClass("active"); $(".x-navbar .desktop ...

Ways to eliminate the leading bullet point from an unordered list

I am currently working on creating a gallery of images using php and css. The images are placed in an unordered list as shown below: <ul style="list-style-type:none;"> <? while($data=mysql_fetch_row($result)) { $pic=$data[2]; if ($pic) { $ ...

JavaScript 12-hour Clock Displaying 24-hour Format with AM/PM Error

I am using JavaScript to display a 12-hour digital clock that updates continuously. However, the code I found online resulted in a 24-hour clock and incorrect am/pm output. Currently, it displays 13:33 am. I have experimented with various code snippets, in ...

How to center an HTML header

Currently working on a one-page scrollable website, aiming to have the first page consist of a navbar, image, and header. The challenge I'm facing is centered around aligning the header vertically. Although I managed to center it horizontally, the ver ...

Problem with resizing in CSS and jQuery

I need help creating a chatbox that can be resized. I've almost got it, but the bottom part of the chatbox detaches when I resize it. Also, I'm having trouble making the userList a fixed size that won't be affected by resizing. Check out th ...

Tips for effectively handling checkboxes created by ezMark:

Incorporating the ezMark library into my website with PHP, Smarty, and jQuery has been a challenging yet exciting task. On a particular webpage, I am faced with the need to disable certain checkboxes based on specific conditions. Moreover, there is a paren ...

Whenever I incorporate a media query in my CSS, I find that I am losing some of the stylings

Recently, I've started using media queries in my application to ensure that the webpages are responsive. It's a new concept for me and I'm still learning how to properly implement it. Below is an example of how I am incorporating media quer ...

Creating a Full-Width Search Input in Bootstrap 4 Navbar

Is there a way to extend the search input width to 100% in the navbar? https://i.sstatic.net/R1Nyi.png The search input field currently has a limited width: <nav class="navbar navbar-light navbar-dark bg-inverse"> <a class="navbar-brand" href ...

Transferring HTML content through AJAX to a PHP script for database storage. The data gets saved correctly, up to "&nbsp;" limit

i have a javascript code that submits HTML form content: $.ajax({ url : 'include/speakers.php', type : 'POST', data : "htmlText="+htmlField", dataType : 'html', success : function ( ...

The challenge of styling React components

Starting a new project with React and Redux has presented me with the challenge of deciding on a styling method. As a newcomer to React, I want to choose a method that won't compromise performance, will offer all CSS3 features, and is easy to maintain ...

What are the steps to creating a rolling item animation?

body { margin: 0px; } .items_container { display: flex; align-items: center; width: 100%; height: 50px; background-color: rgb(200,200,200); } .circle_c ...

Simple method for transforming &#XXXX; from HTML to UTF-8 XML, whether through code in .Net or with the help of various software solutions

These examples are provided to show that HTML and XML are not the same. When an HTML file is inputted, it looks like this: <p class=MsoNormal style='tab-stops:.5in'><b><span style='mso-tab-count:3'> </span>< ...