Adjust the heights of certain headers in an HTML table, not all of them

Here is the link to my JSBin: https://jsbin.com/xofaco/edit?html,css,output

I am facing an issue with an HTML table that has both nested headers and regular headers. My goal is to make all headers equal in height, specifically I want columns labeled "four, five, six" to match the height of the "Admissions" nested header.

I have tried a solution where I used empty <th></th> elements with borders to create the illusion of equal height, but that is not the ideal approach for me.

The code snippet below demonstrates my current setup. Feel free to review the JSBin link provided above for more context or let me know if additional information is required.

table {
  border: 1px solid black;
}

th, td, tr {
  border: 1px solid black;
}

.one {
  border: 1px solid red;
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<div class="table-wrapper table-wrapper--no-scroll table-wrapper--row-header-border table-wrapper--no-cell-wrapping">
  <table>
    <thead>
      <tr>
        <td rowspan="2">&nbsp;</td>
          <th colspan="3" scope="colgroup" class="table-wrapper--no-top-border">Admissions Top Heading</th>
      </tr>
      <tr>
          <th scope-"col" class="table-wrapper--no-top-border">one</th>
          <th scope-"col" class="table-wrapper--no-top-border">two</th>
          <th scope-"col" class="table-wrapper--no-top-border">three</th>
          <th scope-"col" class="one">four</th>
          <th scope-"col" class="one">five</th>
          <th scope-"col" class="one">six</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">March 2016</th>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
      </tr>
      <tr>
        <th scope="row">April 2016</th>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>##&t;/td>
      </tr>
      <tr>
        <th scope="row">May 2016</th>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
        <td>###</td>
      </tr>
    </tbody>
  </table>
</div>
</body>
</html>

Answer №1

Modify your HTML layout by relocating columns four, five, and six to the first tr. Additionally, after moving them, change the th tags to td with rowspan="2".

Ensure that your initial tr appears as follows. You can view the updated version in this link.

<tr>
  <td rowspan="2">&nbsp;</td>
  <th colspan="3" scope="colgroup" class="table-wrapper--no-top-border">Admissions Top Heading</th>
  <td rowspan="2" scope- "col" class="one">four</td>
  <td rowspan="2" scope- "col" class="one">five</td>
  <td rowspan="2" scope- "col" class="one">six</td>
</tr>

Below is a functional code snippet

table {
  border: 1px solid black;
}
th,
td,
tr {
  border: 1px solid black;
}
.one {
  border: 1px solid red;
}
<table>
  <thead>
    <tr>
      <td rowspan="2">&nbsp;</td>
      <th colspan="3" scope="colgroup" class="table-wrapper--no-top-border">Admissions Top Heading</th>
      <td rowspan="2" scope- "col" class="one">four</td>
      <td rowspan="2" scope- "col" class="one">five</td>
      <td rowspan="2" scope- "col" class="one">six</td>
    </tr>
    <tr>
      <th scope- "col" class="table-wrapper--no-top-border">one</th>
      <th scope- "col" class="table-wrapper--no-top-border">two</th>
      <th scope- "col" class="table-wrapper--no-top-border">three</th>

    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">March 2016</th>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
    </tr>
    <tr>
      <th scope="row">April 2016</th>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
    </tr>
    <tr>
      <th scope="row">May 2016</th>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</td>
      <td>###</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

Conceal the icon for the Dropdown Menu arrow

Is there a way to hide the old arrow icon in the Select (drop down) after changing it with a new one? HTML: <div class="row"> <div class="col-sm-12"> <select name="country" class="form-control SearchBar"> <option ...

Check the input in the text box against the selected options to validate it

Currently, I am working on an add contacts page where I am facing the challenge of displaying an error message or highlighting input as invalid if a user tries to enter a contact name that already exists. It seems like one solution could be populating a s ...

Modifying the href attribute of links within various occurrences of an element using jQuery based on its content

Here is an illustration of a recurring element on a webpage <td class=" market all"> <a href="linktosomesite?param=123" target="_blank">123</a> </td> Similar elements change the parameter, resulting in links like: <td clas ...

Form Validation in JavaScript Continues to Submit Form Even When 'False' is Detected

Here is the issue at hand - I am restricted to using older browsers (IE8 and FF8) by corporate policy. Despite my research indicating otherwise, it seems like this might be the root cause of my troubles. My current setup includes PHP 5.5.12 on Apache 2.4. ...

What is the most effective way to toggle the visibility of these rows within a table?

Initially, my plan was to incorporate collapsible rows into my table. However, considering the spacing and margins, I realized that approach wouldn't work. After some thought, I concluded that all I really need is a way to hide and show information on ...

Java Spring - The on-page styling is out of control

Currently, I am in the process of developing a taxi web application using Java Spring. After successfully creating the website with the help of a template, I encountered an issue when trying to integrate the login functionality. Strangely, the styling on ...

Tips for repairing buttons in the CSS container

The buttons in the CSS search-box are not staying fixed as intended. They should be within the search box, but instead, they are protruding out of the panel. I attempted to utilize z-index, but it did not produce the desired outcome. https://i.sstatic.n ...

Could not find the element using the specified cssSelector

I am attempting to locate and interact with this specific div element. <div class="leaflet-marker-icon marker-cluster marker-cluster-small leaflet-clickable leaflet-zoom-animated" style="margin-left: -6px; margin-top: -6px; width: 12px; height: 12px; o ...

Having trouble with the dropdown menu in Bootstrap?

I'm having trouble creating a responsive dropdown menu. When I click on the dropdown items, nothing happens. Here's the code: <div class="navbar-header"> <button type="button" class="navbar-toggel" data-toggel="collapse" data-target="#m ...

How can you assign a strokeStyle color to a Canvas using a CSS property?

Our team is currently working on an Angular2 / Ionic 2 project where we have implemented a HTML Canvas element that allows users to draw on it. One challenge we are facing is how to set the Canvas strokeStyle property using a color provided by a CSS style. ...

Is it possible for a div nested within another div to still occupy space on the page despite being set

<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $("select#choosebook").change(function(){ $(".title").slideDown(" ...

Position the button to the right using the Bootstrap float-right class

Currently, I am utilizing reactstrap within my React component. My primary intention is to position a button to the right side of the container but unfortunately, the following code doesn't achieve the desired result: <td class="col-md-4 clearfix" ...

CSS for Centering Text and ImageAchieving the perfect alignment

I have a footer positioned at the bottom of my webpage containing some text along with a few PNG images. I am attempting to center everything within the footer. I tried using margin: 0 auto, but it didn't work due to the footer not being a block elem ...

Error in External JavaScript File and Uncaught Reference Error

Wanting to utilize a separate Javascript file with my HTML code, I encountered an issue. Here is the code for the HTML document: <!DOCTYPE html> <html> <a href="javascript:showAlert()">Show Alert!</a> <script type="text/jav ...

What is the best method for incorporating separate CSS files for individual HTML templates within a Flask project?

I am embarking on a Flask project and want to keep things organized by having a separate css file for each html file. Most tutorials available online suggest placing all the CSS code in one /static/styles.css file. However, when I try to run the following ...

Tips for submitting a form using javascript while preventing the default action

Looking for a way to submit a form in Javascript and prevent the default action? Let's explore how you can achieve this. Initially, my HTML form with the ID "contact_form" had an input element like so: <input id="contact_send_msg" type="submit" val ...

What is the best way to align my Navbar in the center?

Previously, I searched on this platform for solutions but couldn't find anything that worked. Currently, I am using the Bulma Framework which is not very well-known. However, I need assistance in aligning the brand link on the navbar to the center. Be ...

Grid numbering with CSS in jQuery mobile design

Looking to create a numbered grid where the user inputs a number and the grid is generated. I am considering using CSS, HTML, or Jquery Mobile for an iPad project. I'm unsure of the best approach at the moment. I would like the grid and numbers to aut ...

What is the process for storing form data into a text file?

Despite seeing similar questions in the past, I am determined to get to the bottom of why this code isn't functioning as expected. My goal is to input form data into a .txt file using a post request. While I lack extensive knowledge of PHP, I am pieci ...

What is the process for determining the area of the section?

Take a look at this page as an example - scrolling down on responsive devices reveals related navigation areas which I aim to change with scrollspy (affix fixed navigation). Having a bootstrap navbar, when on the corresponding section of the navbar while u ...