Create a grid or flex layout with Bootstrap 4 that features a sticky first row and column

Does anyone have any suggestions on how to make the attached grid/table layout responsive using Bootstrap 4's flex/grid system? The layout should include a sticky first row and column for navigation items.

I attempted using w- & h- classes, but it doesn't respond well without media queries. I'm looking for the best solution using Bootstrap 4.

Thank you! :)

(Please excuse any mistakes in my English...)

Answer №1

How to Freeze the First Row and First Column

If you want to achieve the freeze effect for both the first row and the first column in a table, you need to extract these elements from the table structure and adjust their positions dynamically based on the scroll behavior of the table body.

 $(document).ready(function() {
      $('tbody').scroll(function(e) { 
        $('thead').css("left", -$("tbody").scrollLeft());
        $('thead th:nth-child(1)').css("left", $("tbody").scrollLeft()-5); 
        $('tbody td:nth-child(1)').css("left", $("tbody").scrollLeft()-5); 
      });
    });

    
   
body {
      margin: 0;
    }
    th, td {
        text-align: center;
        background-color: white
    }
    table {
      position: relative;
      width: 400px;
      overflow: hidden;
    }
    thead {
      position: relative;
      display: block;
      width: 400px;
      overflow: visible;
    }
    thead th {
      min-width: 80px;
      height: 40px;
    }
    thead th:nth-child(1) {
      position: relative;
      display: block;
      height: 40px;
      padding-top: 20px;
    }
    tbody {
      position: relative;
      display: block;
      width: 400px;
      height: 90px;
      overflow: scroll;
    }
    tbody td {
      min-width: 80px;
    }
    tbody tr td:nth-child(1) {
      position: relative;
      display: block;
    }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>ID</th>
          <th>Tanggal</th>
          <th>Judul Pekerjaan</th>
          <th>Deskripsi</th>
          <th>Level</th>
          <th>Category</th>
          <th>Severity</th>
        </tr>
      </thead>>
    
      <tbody>
        <tr>
          <td>1</td>
          <td>1 May 2017</td>
          <td>Satu</td>
          <td>Satu</td>
          <td>5</td>
          <td>Lorem</td>
          <td>Ipsum</td>
        </tr>
        <tr>
          <td>2</td>
          <td>2 May 2017</td>
          <td>Dua</td>
          <td>Dua</td>
        </tr>
        <tr>
          <td>3</td>
          <td>3 May 2017</td>
          <td>Tiga</td>
          <td>Tiga</td>
        </tr>
        <tr>
          <td>3</td>
          <td>3 May 2017</td>
          <td>Tiga</td>
          <td>Tiga</td>
        </tr>
        <tr>
          <td>2</td>
          <td>2 May 2017</td>
          <td>Dua</td>
          <td>Dua</td>
        </tr>
        <tr>
          <td>3</td>
          <td>3 May 2017</td>
          <td>Tiga</td>
          <td>Tiga</td>
        </tr>
        <td>3</td>
          <td>3 May 2017</td>
          <td>Tiga</td>
          <td>Tiga</td>
        </tr>
      </tbody>
    </table>

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

I'm curious about where to find more information on this new technology called the 'scroll to page' feature

Recently, I came across a captivating website feature that caught my eye. As someone relatively new to front end web development, I am intrigued by the scrolling technique used on this site. I'm specifically drawn to the 'page to page' scro ...

What is the method for sending parameters to PHP from an HTML file using AJAX?

My protfolio.html file contains a table #gallery with different categories. I want to dynamically update the content of the #gallery based on the selected category using ajax. I have a php file that scans a specific folder for images related to the categor ...

Is it feasible to create a doughnut chart with curved edges?

My goal is to create a doughnut chart, but my search for reliable CSS/SVG/Canvas solutions has not been successful. https://i.sstatic.net/Rq6Lx.jpg I want each segment to have fully rounded corners, which presents a unique challenge. ...

What is the best way to ensure that all of my images are the same size?

I've been working on making my pictures of varying resolutions the same size here, but no matter what I try, it just doesn't seem to work. Here is what I'm getting: . When I change the state to 1, 2, 3, or 4, I want it to look like this: her ...

Site with Three Steady Columns

While I know that this question has been asked in the past, I'm eager to see if there have been any recent changes. I am currently searching for a fixed 3 column layout using html/css, with the main content (middle) area being located first in the DO ...

Align the items in the center of a Bootstrap navigation bar

I am looking to center the navigation menu items on my navbar. Currently, my navbar layout appears like this: https://i.sstatic.net/BqRwW.png Specifically, I want "Users", "Admin", and "Records" to be centered within the navbar. Additionally, I would lik ...

Can HTML5 be used to store IDs in PHP chat applications?

I'm in the process of developing a chat application with PHP. Everything is functioning properly, but I have encountered a potential loophole. I am implementing AJAX to fetch chat data as the user scrolls, similar to platforms like Facebook and Twitte ...

Image superimposed with vertical dimension

I have a photo with specific dimensions and I want to create a div box with a button inside the image, similar to what is shown in this example: Example Image Here is my current code attempt: .wrapper { width: auto; text-align: center; } .wrapper: ...

Divs are not properly positioned

I’m struggling to align three divs in a row, each with unique cosmetic styles. Two have images on the left and right sides, while the middle one contains a text-filled div. While I’ve managed to fit the image in the divs just fine, the middle div with ...

Is there a way to make text within a Div selectable even if it is positioned behind another Div with a higher z-index?

Currently grappling with some code, unfortunately cannot easily paste the problematic part here as I am unsure of its exact location. Here's the situation: there is a div containing text that needs to be selectable, however, there is another div with ...

Shift attention to the subsequent division after a correct radio option or text input has been submitted

I need to enhance the user experience on my form. When a user interacts with specific elements like hitting enter in a text input or clicking a radio button, I want to automatically focus on the next "formItem" division. My form structure is organized as ...

Issue with text decoration in Html, Css, and Bootstrap

this image shows the issue Hi there, I'm facing an issue with my project involving bootstrap. Whenever I include bootstrap in my project using a link, all "a" tags end up with text decoration. How can I fix this problem? ...

Deactivate user input depending on a certain requirement

Greetings everyone, I am currently working with the following code snippet: <table class="details-table" *ngIf="peop && peopMetadata"> <tr *ngFor="let attribute of peopMetadata.Attributes"> <td class="details-property"&g ...

Selenium is unable to activate the button element by clicking

I have been using Selenium with Python and attempting to click a button, but it simply isn't working. Here is the relevant HTML: <div class="nmMym"> <button class="sqdOP yWX7d _8A5w5 " type="button"> ...

Adjusting the width of columns in a table

Previously in Bootstrap 3, I was able to use col-sm-xx on the th tags within the thead to resize table columns as needed. However, this functionality is no longer available in Bootstrap 4. How can I achieve a similar effect in Bootstrap 4? <thead> & ...

PHP form does not seem to be vulnerable to cross-site scripting attacks

On one of my web pages, I have a form with an action php page using the following html syntax: <form name="form" action="test.php" method="get"> I decided to make it more secure by modifying it to: <form name="form" action="<?php echo htmlsp ...

Creating a stylish border for a div element

Having trouble with styling a border around a div box. I'm struggling to find a way to prevent the borders from looking like this: Let me show you an example of what I'm dealing with: .num.num_1 { border-left-color: #0D2431; } .num { wid ...

Stacking the FontAwesome icons on a PrimeNG button

I've been experimenting with various methods to incorporate stacked icons on a pButton in Primeng, but I haven't had any success. Does anyone have a solution that doesn't result in the button being twice its normal height? Here are a couple ...

The required widths of table columns are not being adhered to

I'm struggling to create an HTML email that will display correctly in Outlook. I initially used list items and the list-style-image Property, but that doesn't work in Outlook. Essentially, I have a table with 2 rows. The left row has an 11 pixel ...

What steps can I take to modify my webpage, like a dashboard, on the internet?

Whenever I click on a menu item in the sidebar of my HTML file, I want only the body section to change without affecting the navigation or sidebar content. For instance, if I select the "Coding Convention" menu in the sidebar, I would like the page to swi ...