When creating a table using Bootstrap HTML, I noticed that the first row is merging with the table header

I am trying to create a bootstrap table in HTML, but I'm facing an issue where the first row merges with the table header, making it look unappealing. I've attempted to use offsets, but they don't seem to solve the problem. My goal is to have a fixed header table that remains in place when scrolling.

Below is the code I have written. Can you please provide guidance on how to fix this issue:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>


<style>

    body{
}
.table-fixed{
  width: 100

  tbody{
    height:900px;
    overflow-y:auto;
    width: 100%;

    }
  thead,tbody,tr,td,th{
    display:block;
  }
  tbody{
    td{
      float:left;
    }
  }
  thead {
    tr{
      th{
        float:left;

      }
    }
  }
} 


    th,td {
        width:12.5%;  /*100% number of Cloumn*/
    }

</style>

</head>
<body>


    <div class="container">
  <table class="table table-fixed">
    <thead style="position:fixed" data-offset-top="10">
      <tr>
        <th class="col-xs-1">First Name</th>
        <th class="col-xs-1">Last Name</th>
        <th class="col-xs-1">E-mail</th>
        <th class="col-xs-1">E-mail</th>
        <th class="col-xs-1">E-mail</th>
        <th class="col-xs-2">E-mail</th>
        <th class="col-xs-1">E-mail</th>
        <th class="col-xs-4">E-mail</th>

      </tr>
    </thead>
    <tbody>
         // Additional rows left out for brevity

    </tbody>
  </table>
</div>


</body>

</html>

Answer №1

remove this :

<tgroup style="position:fixed" data-offset-top="10">

Avoid using <tr><th> for table rows. Reserve it only for headers.

Below is a fully functional code example:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
    <div class="container">
  <table class="table table-fixed">
    <thead style="position:fixed" data-offset-top="10">
      <tr>
        <th class="col-xs-1">First Name</th>
        <th class="col-xs-1">Last Name</th>
        <th class="col-xs-1">E-mail</td>
        <th class="col-xs-1">E-mail</td>
        <th class="col-xs-1">E-mail</td>
        <th class="col-xs-2">E-mail</td>
        <th class="col-xs-1">E-mail</td>
        <th class="col-xs-4">E-mail</td>

      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="col-xs-1">dd</td>
        <td class="col-xs-1">sdffff</td>
        <td class="col-xs-1">E-mail</td>
        <td class="col-xs-1">E-mail</td>
        <td class="col-xs-1">E-mail</td>
        <td class="col-xs-2">E-mail</td>
        <td class="col-xs-1">E-mail</td>
        <td class="col-xs-4">E-mail</td>
      </tr>>
        <!-- additional rows here -->
  </table>
</div>
</body>
</html>

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

Javascript Snake: I am having trouble making my snake's tail grow longer

I've created a snake game that is almost fully functional. The issue I'm facing is that when the snake eats food, the food changes location but the tail of the snake doesn't grow in size. I suspect that my understanding of arrays might be la ...

The Bootstrap 4.5 grid system

Something strange is happening... I was trying to set up a webshop with 4 products in a single row while using Bootstrap 4.5, but encountered an issue: see image here The image doesn't fit inside the boxes properly and there's too much space bet ...

when implementing react-native-tesseract-ocr in your project:

Attempting to run the Android application... [email protected] android react-native run-android Information: JS server is already running. The app installation process is in progress. This build contains deprecated Gradle features that are incompa ...

Combine and store downloaded stylesheets in the browser into a single file

My task involves transforming a website page along with all its external stylesheets into a single HTML file with inline CSS. This is not for usage in emails, but rather to incorporate styled sections of that page into another website's page. After so ...

Every time I refresh the app, I am consistently redirected back to the home route "//"

I'm facing an issue where, after logging in successfully, I get redirected to the homepage. However, when I refresh the page from any route other than the homepage, such as "/products", I always end up getting redirected back to "/". This is what my ...

Two divs with floated attributes and equal heights

My unique HTML is below: <div class="container"> <div class="box"> <div class="float"> <img src='http://media-cdn.tripadvisor.com/media/photo-s/03/9b/2f/db/miami-beach.jpg' /> </div> ...

Having trouble with rendering components in React and Bootstrap?

Attempting to display basic Bootstrap components using React. This corresponds to the index.html file: <!doctype html> <html> <head> <script src="http://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="j ...

Unique color selection for progress bars in Bootstrap Vue

Can the color of a progress bar be customized to any specific value in hexadecimal format? The preset colors like 'success' or 'danger' are not meeting our requirements, so I need to define my own color for the progress bar using a hex ...

Beginner in CSS Structuring

Hey there, I'm facing a bit of a challenge and could really use some guidance. I'm trying to design a layout for a website with specific components, but I can't seem to achieve the exact look I want. I know it should be straightforward, but ...

Adjusting the Aspect Ratio of an Embedded YouTube Video

<!DOCTYPE HTML> <head> <style> body { overflow: hidden; margin:0; } </style> </head> <body> <iframe id="video" src="https://www.youtube.com/embed/U4c9bBeUe4M?modestbranding=1&sh ...

Utilizing @media queries in a unique React setup that involves a mixture of .tsx and .ts files

I have been immersed in the world of React for a good couple of years now, and have also dabbled in @media queries since the early 2000's. Recently, I joined a new project where they are taking a unique approach to building React components that is qu ...

Adding HTML code to a file with PHP

Looking for help with a Javascript function that sends a string through ajax to a PHP page. The goal is to insert this string into the existing head tag of an HTML file using PHP and ensure that the change is permanent. Any guidance on how to manipulate ...

Ways to extract information from a dynamically generated table

I'm facing an issue with retrieving data from a dynamically generated table within my script... Here is the code snippet: $('#update_panel').html('Loading Date....'); $.ajax({ url: '/Home/GetCountries', type: & ...

utilize javascript to parse and access data from the xml.aspx file

After using F12 in Firefox, an error "NS_ERROR_FAILURE" appeared for html:16 (xml.send();). The opensource website suggests using HTTPS request method: GET. Why is there an error even when following these instructions? Any insight is appreciated. Thanks! ...

What are some effective ways to utilize localstorage efficiently?

I've been working on creating a variable that stores its value across multiple pages using local storage. However, I've encountered an issue where the variable is not being saved, and there are no error messages to help diagnose the problem. Her ...

Apply multiple CSS properties to elements by extracting the innerHTML

I am currently trying to apply some CSS to certain div elements on my webpage. Here is the HTML code snippet: <div class="data-item"> <a class="title" id="cms-occasion" style="font-size: 14px !important;" href="#">Gift for a Graduate</ ...

Automatically Dismissing a Bootstrap Alert After a Set Number of Seconds

Having some trouble closing a Bootstrap alert automatically on my new site built using the Bootstrap Framework. The issue arises when trying to close the alert after a certain amount of time. On the main page of the site, there is a modal login form. When ...

React-Webcam: What is the solution for the error "Object may be null" and how to resolve "Type null is not compatible with type string or undefined"?

I'm encountering an issue with const imageSrc = webcamRef.current.getScreenshot(); Error: Object is potentially 'null'; and src={imgSrc} <img src={imgSrc} /> Error: Type 'null' cannot be assigned to type 'string | und ...

Selenium - pausing for scroll completion

I am currently working on automating downloads from a webpage using the selenium tool. My approach involves creating a firefox driver that opens the page and clicks the download button. However, I have encountered an issue where the button needs to be vis ...

Capybara - Navigating a page by clicking on a link related to another value

I'm currently facing a challenge in locating and selecting a particular link on a web page. All links within an HTML table contain the term 'Edit' (it's a link for editing configuration settings). However, the exact link changes depend ...