Solving the problem of the fixed header in bootstrap tables

With bootstrap, I am attempting to make a fixed table header that does not scroll along with the content. Can someone assist me in achieving this?

Here is a snippet of my code:

This is my code:

  <div class="widget-content">
          <div class="container">
            <table class="table table-bordered">
              <thead>
              <th class="text-center"> my</th>
              <th class="text-center"> text / line</th>
              <th  class="text-center">caps/ lock</th>
              <th  class="text-center">Value</th>
              <th  class="text-center">Qty</th>
              <th  class="text-center">other</th>
              </thead>
              <tbody>

                <tr class="dt-picked">
                  <td class="text-center">
                      <span style="color:white; font-weight:bold;"> text</span>

                  </td>
                  <td class="text-center">
                    <p>text</p>

                  </td>
                  <td class="text-center ">
                    <p>text</p>
                   <p>text</p>
                  </td>
                  <td class="text-center"> <p>text</p></td>
                  <td class="text-center b-color-1"><p>text</p></td>
                  <td>
                    class="btn btn-mini btn-danger" role="button">Sell</a>
                  </td>
                </tr>

              <tr>
                <td colspan="4" class="text-right no-stripe">Total Cash</td>
                <td class="b-color-1"><p>text</p></td>
              </tr>
              <tr>
                <td colspan="4" class="text-right no-stripe">Total Invested</td>
                <td class="b-color-1"><p>text</p></td>
                <td colspan="2" class="no-stripe"></td>
              </tr>
              <tr>
                <td colspan="4" class="text-right bold no-stripe">Bottom Line</td>
                <td class="b-color-1 bold"><p>text</p></td>
                <td colspan="2" class="no-stripe"></td>
              </tr>
              </tbody>
            </table>
          </div>
        </div> 

Answer №1

Here is a fiddle I have prepared for you

<thead>
    <tr class="header">
      <th>
        Attribute Name
        <div>Attribute Name</div>
      </th>
      <th>
        Value
        <div>Value</div>
      </th>
      <th>
        Description
        <div>Description</div>
      </th>
    </tr>
  </thead>

Check out the fiddle here!

Answer №2

Consider implementing the position Property on the thead element

<thead style="position:relative;">
              <th class="text-center"> my text</th>
              <th class="text-center"> line of text</th>
              <th  class="text-center">all caps</th>
              <th  class="text-center">Value</th>
              <th  class="text-center">Quantity</th>
              <th  class="text-center">more</th>
              </thead>

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

A guide on choosing a custom button color and automatically reverting to its original color when another button is clicked

I have a collection of 24 buttons, all in a dark grey (#333333) shade. Whenever I click on one of the buttons, it changes to a vibrant blue color (#0099ff), which is functioning correctly. However, when I proceed to click on another button, the previous ...

CSS: Have you ever wondered why :not() doesn't work unless you specify the tag type?

Here's the code I'm working with: * { font-size: 30px; } .day { color: gray; } .today { color: blue; } :not(.today) .date { color: orange; } <span class="day">Tuesday<span class="date"> • 4</span></span> &l ...

What is the best way to disable the appearance of an HTML checkbox?

Is there a way to make a checkbox readonly, but still have it appear disabled or grayed out? I want it to function like this: <input type="checkbox" onclick="return false;"> If anyone knows how to accomplish this, please share yo ...

Angular Bootstrap 4 modal with responsive content dimensions

I am facing an issue where I am trying to place a media list inside a Bootstrap card. However, when I zoom in on the browser, the media list <ul/> overflows from the modal-body and goes out of the Bootstrap card. How can I ensure that the media list ...

Developing several sliders and ensuring they operate independently of each other

I am currently in the process of developing multiple sliders for a website that I am building. As I reach the halfway point, I have encountered a problem that has stumped me. With several sliders involved, I have successfully obtained the length or count ...

Stop vuetify from cluttering the global style scope

Seeking to embed a Vue component into another from an external source without using a Vue Plugin. The components are mounting correctly, but the embedded component's use of Vuetify is affecting the parent application's style. Visual examples can ...

When adjusting window size, the input shifts towards the left

Is there a way to prevent my input and login button from moving to the left when resizing the window? I am new to HTML and CSS and would appreciate any tips on keeping them in place. Below is my CSS code: #absolute { position: absolute; top: 411px; le ...

Tips on rearranging the location of a div element within a directive

I have created a custom directive that displays two divs, Div1 and Div2, with a splitter in the middle: Splitter Image Now, I am looking for a way to swap the positions of these two divs dynamically using an Angular directive. I thought about using ng-swi ...

Get the div to occupy the rest of the available height

I am facing a challenge with two divs on my webpage. The bottom one contains content that expands the highest. The page is set to 100% height and width using the CSS property position: absolute. <style> body, html { height:100%, width:100% } ...

Does Google Chrome have a strange way of interpreting CSS?

Almost done with my website and it looks great on Firefox and IE 8, but Chrome is causing issues. Here's how it appears on FF: And here's Chrome: Notice how Chrome resizes the first image even though the code is the same as the one below? Che ...

What is the best way to isolate the CSS of individual components in Angular 2?

For the first component: CSS-- ngx-dnd-container { color:black; background-color: white; } HTML- <ngx-dnd-container [model]="targetItemsA" dropZone="multiple-target-a" </ngx-dnd-container> For the sec ...

Adding padding with and without child elements

As I work on styling a basic menu, I'm struggling to find a solution for adding padding to list items so they all have a consistent look. The challenge arises from the fact that I have an unordered list where list items may or may not contain an anch ...

How to keep a div element fixed on the page's border vertically and horizontally adhered

Would you mind visiting the following link: and observing the layout of the page? My goal is to affix or "attach" a small div element to the right side of the page, just slightly outside of the right frame of the page. Vertically, I want this div to be ...

When using Angular with mdbootstrap, the mdb-tabs directive will move to the end if the ngIf condition is true

Currently facing a challenge with a significant amount of code here. It is referenced as follows: "ng-uikit-pro-standard": "file:ng-uikit-pro-standard-8.3.0.tgz", I am attempting to display a tab between 1 and 3 if a certain condition ...

What is the best method for properly showcasing WordPress database values in a table?

Using wordpress, I have set up a system where users can sign up for tasks associated with a project. Each project can have multiple tasks, and users' usernames are stored in a meta table in the database under the corresponding task key. Multiple users ...

Unexpected behavior: getElementById returning URL instead of element

I created a function that accepts a thumbnail path as an argument, waits for the bootstrap modal to open, and then assigns the correct path to the thumbnail href attribute within the modal. However, when I use console.log with the element(el), it displays ...

Customize Bootstrap radio buttons to resemble standard buttons with added form validation styling

Is there a way to style radio buttons to look like normal buttons while maintaining their functionality and form validation? I have two radio buttons that need styling but should still behave like radio buttons. Additionally, I am utilizing Bootstrap for s ...

Create a styled-components component that renders a cross inside a recognizable object surrounded by borders

Currently developing an Object Recognition app and aiming to add a border around the object along with a cross that indicates the center. The border has been successfully implemented, but having trouble creating the cross. The plan is to add two more boxes ...

How to Retrieve the Url of a Clicked Element using CSS Property

Is it possible to retrieve the URL when a link is clicked using CSS alone, without relying on JavaScript or jQuery? ...

Scroll horizontally within the div before scrolling down the page

After reviewing other questions, it's important to note that the scroll I am looking for is horizontal, not vertical. My goal is to have a div on a page automatically start scrolling when it reaches the center or becomes visible, and then allow the pa ...