Issues with table header causing columns not to display at full width

I'm currently working on creating a table with a scrollbar within the body of the table. Below is the code I have written for this purpose. While the scrollbar functions properly, there seems to be an issue with the columns in the thead section. They appear significantly smaller than the columns in the tbody section which uses 100% of the width. Can anyone provide insight as to why the layout works correctly for the body but not the header?

<table style="width:100%;">
  <thead style="width:100%;display:block;"> 
    <tr>
      <th style="width:70%;">Description</th>
      <th>Task appears on</th>
    </tr>
  </thead>
  <tbody style="width:100%; height:300px;overflow-y:scroll;display:block;">
    <tr>
      <td style="width:70%;">Test1</td>
      <td> Test2</td>
    </tr>
  </tbody>
</table>

<table class="dash-task-list" style="width:100%;"><thead style="width:100%; display:block;"> <tr><th class="dash_description" style="width:70%;">Description</th><th class="dash_tasks_appear">Task appears on</th></tr></thead><tbody style="width:100%; height:300px; overflow-y:scroll; display:block;"></tbody></table>

Answer №1

UPDATED SOLUTION

Your problem is now resolved! Best of luck to you.

.first-td{
  width:70%
}

.second-td{
  width:30%
}

tbody tr{
  display: flex
}
<table style= "width:100%">
  <thead>
    <tr >
      <th class="first-td">Column 1</th>
      <th class="second-td">Column 2</th>
    </tr>
  </thead>
  <tbody style="display:block; width:100%; position:fixed; overflow: auto; height: 100px;">
    <tr>
      <td class="first-td">row 2-0</td>
      <td class="second-td">row 2-1</td>
    </tr>
    <tr>
      <td class="first-td">row 2-0</td>
      <td class="second-td">row 2-1</td>
    </tr>
    <tr>
      <td class="first-td">row 2-0</td>
      <td class="second-td">row 2-1</td>
    </tr>
    <tr>
      <td class="first-td">row 2-0</td>
      <td class="second-td">row 2-1</td>
    </tr>
    <tr>
      <td class="first-td">row 3-0</td>
      <td class="second-td">row 3-1</td>
    </tr>
    <tr>
      <td class="first-td">row 4-0</td>
      <td class="second-td">row 4-1</td>
    </tr>
    <tr>
      <td class="first-td">row 5-0</td>
      <td class="second-td">row 5-1</td>
    </tr>
    <tr>
      <td class="first-td">row 6-0</td>
      <td class="second-td">row 6-1</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

Steps for assigning a default attribute to all elements

Let's take a look at this code snippet: <form> <input type="text" required="true"> <input type="text" required="true"> <button type="submit">Click</button> </form> Do you think there is a way to assign a def ...

Issue with nivo-lightbox not opening upon clicking image

I have diligently followed the instructions to set up this JavaScript plugin, but unfortunately it doesn't seem to be functioning properly. The plugin I'm using can be found here: All the links to the CSS, theme, and JavaScript files are display ...

What could be causing these transformed canvases to not display fully in Chrome at specific resolutions?

fiddle: https://jsfiddle.net/f8hscrd0/66/ html: <body> <div id="canvas_div"> </div> </body> js: let colors = [ ['#000','#00F','#0F0'], ['#0FF','#F00','#F0F&a ...

I'm having trouble connecting my CSS file to my HTML file. It seems to be functioning properly with Live Server, but it's not working on its own. Any ideas on what

Recently, I encountered an issue with my CSS and HTML files. Initially, they were in the same folder on my desktop and the <link rel="stylesheet" type="text/css" href="style.css" /> reference worked perfectly. However, I decided to organize my file ...

Top strategies for effectively handling Bootstrap in Python Flask projects

After putting in the effort to develop a web app using python-Flask and bootstrap for the frontend, I am excited to share my project that enables users to conveniently browse the AWS S3 bucket directly from their web browser. As this project is still a wor ...

jQuery swap- enhancing the appearance of numerical values

I am looking to customize specific characters within my <code> tag. While searching online, I came across the .replace() function but encountered issues when trying to style numbers. My goal is to change their appearance without altering the text its ...

Two CSS files are loaded sequentially

Currently, when my HTML page loads, it first displays the styles from the initial CSS file before switching to the second CSS file. This brief moment where the page appears differently than intended is a bit frustrating. Is there a way to prevent this chan ...

The Best Practices section of the Chrome lighthouse report has identified an issue with properly defining the charset

I recently noticed an error in my VueJs SPA application when running a Chrome Lighthouse report. The error message indicated that the charset was not properly defined, even though I had added it to my index.html file. Below are screenshots of the issue: ...

Ajax calls within nested functions are not being executed in the correct sequence

Currently, I am utilizing the geonames API to retrieve geographical information. My objective is to extract the names of states within a country using the getStateInfo function and subsequently obtain a list of cities in each state through the getCityInfo ...

Loading an animated SVG sprite file in real-time

Recently, I received an SVG sprite file from our designers to use in my app. The specified convention is to load the sprite at the top of the <body> element and then render icons using a specific code snippet: <svg class="u-icon-gear-dims"> ...

Aligning a label in the center of a horizontal layout's vertical axis

Struggling with centering a QLabel vertically in a QHBoxLayout. Here's the relevant part of my code: QFrame* topBar = new QFrame(); topBar->setStyleSheet("background-color: #2c3d50;border-bottom: 3px solid #2c92b6;"); topBar->setSizePolicy(QSiz ...

List formatted in a table

Can a list be inserted into a table using markdown? I attempted to research this but came up empty-handed. An example of a Table: Fruit |Color ---------|---------- Apples |Red Pears |Green and an example of a list: List item 1 List item 2 ...

The Bootstrap Navbar dropdown list appears cluttered on desktops but remains tidy on mobile devices

I am encountering an issue because I haven't studied much about the design aspect. I am currently using a template from w3layouts.com under the Education section, specifically the Tutoring Template. This template is based on Bootstrap. The demo page ...

Styling Material UI height in select elements (React)

Currently, I am developing a react application that utilizes Material Dashboard. I am encountering an issue with the height of a Select (drop-down list) component. See image here On the right side of my app, there is a standard input field and I would li ...

How can I stop a browser from refreshing when I click the mouse?

After taking steps to prevent the browser back button from functioning by clearing history and disabling key events for page refresh, I am now seeking a way to also stop mouse clicks on the browser's refresh button. Can anyone offer assistance with th ...

Background image design for mobile using Bootstrap

On my website, I have a background image set. However, I noticed that when viewing it on a mobile device, the background image appears in different sizes on different pages, even though they are all linked to the same stylesheet and use the same code. You ...

Alter the background image of the body based on the active ID and class

Currently, I am developing a website where all the pages slide around on the main landing page. The process starts with a div having an ID of "main" and a class of "currentpage." When navigating through the menu items, the content slides away to reveal the ...

Navigate through JSON data to add to an HTML table

HTML <table id="id_kbdata" cellspacing="0" cellpadding="0" > </table> JSON [ { "id":"3", "title":"Doing Business In...", "businessSubjectAreas":[ { "businessSubjectArea":"Market and Sell Products/Service" }, ...

Is it possible to fetch all the content contained within each set of <p> and </p> tags within a specific ID?

I've been trying to extract text between two specific <p> tags in HTML, but my code is only returning the text between a single tag. Here's what I have so far: > var myHTMLString = try String(contentsOf: myURL, encoding: .as ...

The $_REQUEST variable is functioning properly, while the $_POST variable seems to

I currently have an HTML form using the post method. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type='text/javascript& ...