The discrepancy in the widths of columns and rows in the table is causing a visual inconsistency

It's been hours and I'm still struggling with a seemingly simple div table. The issue is that the column headers refuse to resize properly to match the width of the table or rows. The rows seem fine, but the headers just won't cooperate.

I don't want to use fixed widths because my next table might have a different number of columns. Currently, the column headers are all bunched up on the left side next to each other, completely out of sync with the rows...


<style type="text/css>

.table-container {
    display: table;
    width: 50%;
    table-layout: fixed;
    border-collapse: collapse;
}

.table-heading {
    font-weight: bold;
    display: table-caption;
    background-color: #e9e9e9;
    text-align: center;
    padding: 8px;
    line-height: 21px;
    font-size: 18px;
    color: #CA8327;
}

.table-row {
    display: table-row;
    text-align: center;
}

.table-row-shade {
    display: table-row;
    text-align: center;
    background-color: #e9e9e9;
}

.table-col {
    display: table-cell;
    text-align: center;
    border: 1px solid #ca8327;
}

</style>

<div class="table-container>
  <div class="table-heading>Approximate Dimensions (inches)</div>
   <div class="table-col>
    <div class="table-col>size</div>
    <div class="table-col>head strap (inc. frame)</div>
    <div class="table-col>chin strap</div>
    <div class="table-col>lbs.*</div>
   </div>  
  <div class="table-row-shade>
    <div class="table-col>XXS</div>
    <div class="table-col>3-9 inches</div>
    <div class="table-col>2-3 inches</div>
    <div class="table-col>< 5 lbs*</div>
  </div>
    <div class="table-row>
    <div class="table-col>XS</div>
    <div class="table-col>5-13 inches</div>
    <div class="table-col>3-7 inches</div>
    <div class="table-col>5 - 10lbs*</div>
  </div>
</div>

http://jsfiddle.net/Speedy1/t3e3ken6/

Answer №1

Make sure to use table-row instead of table-col

<div class="table-container">
  <div class="table-heading">Approximate Dimensions (inches)</div>
   <div class="table-row"> <!-- must be a table-row -->
    <div class="table-col">size</div>
    <div class="table-col">head strap (inc. frame)</div>
    <div class="table-col">chin strap</div>
    <div class="table-col">lbs.*</div>
   </div>  
  <div class="table-row-shade">
    <div class="table-col">XXS</div>
    <div class="table-col">3-9 inches</div>
    <div class="table-col">2-3 inches</div>
    <div class="table-col">< 5 lbs*</div>
  </div>
    <div class="table-row">
    <div class="table-col">XS</div>
    <div class="table-col">5-13 inches</div>
    <div class="table-col">3-7 inches</div>
    <div class="table-col">5 - 10lbs*</div>
  </div>
</div>

http://jsfiddle.net/vgjb578s/

Answer №2

If you're encountering issues, I recommend checking out this JSFiddle link for a potential solution.

The reason for the problem is likely because the "table-col" class is placed next to your heading. To fix it, simply change it to "table-row" and that should resolve the issue.

<div class="table-row">
   <div class="table-col">size</div>
   <div class="table-col">head strap (inc. frame)</div>
   <div class="table-col">chin strap</div>
   <div class="table-col">lbs.*</div>
</div>  

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

Obtaining a URL in JavaScript

Hey there, I'm diving into the world of JavaScript and could use some guidance. I'm currently working on implementing forward and backward buttons on a webpage. The URL structure is http://webaddress.com/details?id=27 My goal is to write two fun ...

Reload the text content of a locally hosted webpage within an iframe at regular intervals

I have set up a simple webpage on my local machine to showcase the contents of some text files on a dedicated monitor. However, I am facing an issue where refreshing the entire webpage causes flickering. My goal is to only refresh the iframes and reload t ...

Designing hover-activated submenus and ensuring they appear at the forefront

I am currently utilizing jquery to implement a dropdown submenu on hover action. Here is the structure of the code: <div id="menucontainer"> <ul id = "topmenu"> <li><a onmouseover="javascript:show('div_1');">menu_1 ...

Ensuring that the two columns in a responsive grid have equal heights is essential for maintaining a

I am currently working on a responsive website with a main content area (.content-wrapper) and a sidebar area (.search-listing). My goal is to make sure that both columns have the same height. I attempted to achieve this using the following jQuery code: j ...

Make sure to keep Typed.js hidden until the Animate.css animation is complete

To create an engaging webpage, I am leveraging Bootstrap, Animate.css, and Typed.js. The desired effect is to have a blank page initially, then make the navigation bar slide down using animate.css fadeInDown. Once this animation completes, the Typed.js lin ...

Having trouble with the contact form sending emails

My contact form box seems to be having trouble directing the mail to my email. When I hit the send message button, it just refreshes the page in a continuous loop. <div class="wow fadeInUp col-md-6 col-sm-12" data-wow-delay="1.6s"> <h1>I ...

Issue found in ./node_modules/bootstrap-loader/no-op.js

I'm currently using Webpack in my application with index.ts as the entry point. I'm incorporating sass, css, bootstrap, and typescript resources into my project webpack setup. However, I've encountered some errors related to the bootstrap-lo ...

Is there a way to implement a floating horizontal scrollbar?

One of the challenges I face with my website is a large table that extends far below the fold, making it inconvenient to access the horizontal scroll bar. Is there a way to keep the horizontal scroll bar floating at the bottom of the window for easier ac ...

JavaScript-powered Chrome Extension designed for modifying CSS styling

Like many others, I've embarked on creating a Chrome Extension to modify the CSS of a specific webpage. Despite reading through various threads, my approach is a bit more complex than what has been discussed. The page I want to style features a sele ...

Adding the active class in Bootstrap can be easily achieved in CodeIgniter by using the

I am seeking guidance on how to add an active class in CodeIgniter when dividing the view into three separate files. These files include: header.php page1.php ... page10.php footer.php According to this thread, there seems to be no clear solution prov ...

Utilizing HTML and JavaScript to Download Images from a Web Browser

I'm interested in adding a feature that allows users to save an image (svg) from a webpage onto their local machine, but I'm not sure how to go about doing this. I know it can be done with canvas, but I'm unsure about regular images. Here i ...

What could be causing the lag in the animation on my mobile device?

I created a CSS animation that runs smoothly on my computer, but I noticed some jerkiness when testing it on my smartphone. Can someone explain why this is happening and suggest ways to fix it? I would like the animation to work on mobile devices as well ...

Adding a placeholder attribute to a file input field

Is it possible to insert a placeholder in an input field that is of type file? I attempted to use the jQuery watermark plugin, but unfortunately it was unsuccessful. ...

Utilizing JQuery's .append() method for dynamically modifying the layout of a table

I have encountered an issue with my HTML table where I want to dynamically change the layout of the table based on the browser size. Here is a snippet of my basic code: <tr> <td class="row">E1</td> <td class="row">E2</td> ...

Exploring Angular 6's nested routes and corresponding components for child navigation

I'm currently diving into the concept of lazy loading in Angular 6. Here's a visual representation of the structure of my application: ─src ├───app │ ├───components │ │ ├───about │ │ ├─── ...

Ways to ensure your page stays confidential

Concept: Exploring the idea of making specific pages on a website private. For example, having 4 navigation links where one link leads to a private page that requires a username and password for access. Currently, my practice website has 7 links directing ...

Creating interactive dialogue: the speech bubble script

I'm having trouble with my code overlapping in sections, and I just can't seem to figure out why. I've tried adjusting borders, adding padding, adjusting spaces, changing widths, reviewing the code, and even removing absolute positions, but ...

Creating a progress bar that includes hyperlinks: A step-by-step guide

Currently, I am in the process of developing an application form that consists of 9 pages of questions. Initially, I had implemented a progress bar which indicated completion by filling up 1/9 for each page completed. However, I have been informed that thi ...

Attempting to showcase the text within an <a> element on a <canvas> element while ensuring there are no noticeable visual distinctions

Imagine having this snippet of code on a webpage: elit ac <a href="http://www.ducksanddos/bh.php" id='link'>Hello world!</a> nunc Now, picture wanting to replace the <a> tag with a <canvas> element that displays the same ...

Is there a way to send the image to the server without having to reload the page?

After loading the picture onto the server, I noticed that the page automatically refreshes. My main objective is to upload the picture without any page refresh. Does anyone have a solution for this issue? In the code snippet below, I tried using onsubmit = ...