Having difficulty sizing specific <td> elements in an HTML table

Is there a way to increase the size of a TD cell without adjusting the height of the entire row? I tried using inline styling with "rowspan= 7", but it only centers the data in the middle of the cell.

I am attempting to create a table similar to the one shown in this image and I'm unsure how to adjust the size of "Some Data" and "Other Data" cells like they are shown..
https://i.sstatic.net/z7fc7.png

table {
  text-align: center;
  border: 1px solid black;
  border-collapse: collapse;
}

td {
  width: 30vw;
  border: 1px solid black; 
}
<table>
  <tr>
    <td></td>
    <td>Heading</td>
    <td>Heading 2</td>
  </tr>
  <tr>
    <td rowspan="8">Some Data</td>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td rowspan="8">Other Data</td>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
</table>

Answer №1

To solve the issue of table cells with rowspan not aligning properly, simply add a class called .rowspan to those cells and apply the following CSS style: vertical-align: top;.

table {
  text-align: center;
  border: 1px solid black;
  border-collapse: collapse;
}

td {
  width: 30vw;
  border: 1px solid black; 
}

.rowspan {
  vertical-align: top;
}
<table>
  <tr>
    <td></td>
    <td>Heading</td>
    <td>Heading 2</td>
  </tr>
  <tr>
    <td rowspan="8" class="rowspan">Some Data</td>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td>X</td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td>546</td>
    <td></td>
  </tr>
  <tr>
    <td rowspan="8" class="rowspan">Other Data</td>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td>Y</td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
  <tr>
    <td>123</td>
    <td></td>
  </tr>
</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

Adjust the dropdown width on a bootstrap form to match the size of the textbox

In order to maintain a combined width of 450px, I have two textboxes. One textbox includes a dropdown menu while the other does not. Both textboxes are part of an input group. The dropdown can switch between either textbox at any time. I need the width ...

Bootstrap link causing alterations to my CSS code

After incorporating Bootstrap into my HTML, I noticed that it caused some unexpected changes to my CSS code. Original CSS: https://i.stack.imgur.com/EsE6J.jpg Modified CSS after applying Bootstrap: https://i.stack.imgur.com/yH1r9.jpg Link to Bootstrap ...

Eliminate unnecessary white space on your webpage using CSS with the 960.gs grid system

As I work on building my portfolio website from scratch, I came across a CSS framework known as "960.gs". While I have experience with similar tools, this is my first time delving into a pure CSS framework, so I'm feeling a bit out of practice. Here ...

Enhancing the appearance of text in an article by using hover effects, while ensuring the link is attached to the

As I work on the design of my website, I am faced with a challenge involving elements that have links attached to them. I want visitors to be able to click anywhere on the article and be directed to a specific page. The code snippet I currently have is as ...

CSS is malfunctioning on IE and Chrome browsers, yet it functions correctly on CodePen when using Chrome

We are experiencing issues with our CSS and HTML not displaying correctly in IE or Chrome. The text is not properly center aligned. Oddly enough, it works fine when viewed through Chrome on CodePen. The text is center aligned there. <html> <hea ...

Query the MySql database with PHP to locate an HTML hyperlink

I am working with a mysql table which has item_id and link columns where the link column contains both html tags and actual links. I need to search the database for a link that does not contain any html tags. What is the most efficient way to achieve thi ...

Placeholder disappears when text color is changed

I have been struggling for 3 hours trying to change the placeholder color to graytext, but it's just not working. Here is the code I've been using: <div class="form-group"> <label for="email">Email:</label ...

Using Jquery .ajax to Populate Select Dropdown with JSON Data

I have put in a lot of effort but I'm not seeing any results. My JSON data, created with PHP, looks like this (with the header sent before the data): {"users":[ {"id":"3256","name":"Azad Kashmir"}, {"id":"3257","name":"Balochistan"}, {"id":"3258","na ...

The scrollbar remains unresponsive and fixed until the screen size is adjusted

Need some assistance with a website project for a client. The scrollbars on each page are not loading or changing height until the window is resized. I have a jQuery scrollbar in place, but disabling it does not solve the issue as the normal scrollbar beha ...

using jQuery to show a block element

I'm attempting to determine whether a div with the style display as block then perform an action. Here is an example: This is just an idea I'm trying to implement using jQuery. if ($("#toshow").css("display") == "block"){ }else{ } ...

Tips for utilizing a personalized extension in Visual Studio Code

Embarking on my HTML journey, so please bear with me. I've been watching tutorial videos to get a better grasp of it, and one of the tutorials I'm following shows how to create a resume on GitHub using VS Code. Check out the video here At 3:44 ...

The vertical scrollbar appears to be malfunctioning

I'm experiencing an issue where the scrollbar is visible but not functioning as expected. I am utilizing CSS for styling the scrollbar and other layouts, along with HTML to apply the styling. #sub_menu, #content{ display: inline-block; } #sub_ ...

Ways to modify the gap between buttons using CSS

I am faced with a design challenge on my home page. I want to add some spacing between the buttons so they are not too close to each other, but for some reason margin-top and margin-bottom properties are not working as expected. Can you help me figure out ...

Issues with JavaScript causing slideshow to malfunction

I'm experiencing some issues with my image slider. It seems that during the initial loop, the slideshow keeps reverting back to 'image3'. However, after the first loop, everything appears to work correctly. I am looking for a solution to ens ...

Using JavaScript to modify a section of an anchor link attribute

I am looking to dynamically update part of the URL when a specific radio button is selected. There are three purchase links, each representing a different amount. After choosing an animal, I need to select one of the three amounts to spend. How can I modi ...

Clicking on a Vuetify v-btn with the :href attribute set to download will open the XML file

I'm having trouble getting the v-btn to download an XML file instead of opening it in the browser. <v-btn :disabled="!exportUrl" block x-large height="100" color="primary" :href="exportUrl" download> ...

sliding to the right gets jammed

I am encountering a peculiar issue with Multi-page slide functionality. Whenever I attempt to switch pages, the new page gets stuck on the left before sliding out into position. Feel free to test this problem using my JSFiddle This is the JQuery code that ...

Issues arise when implementing ReactJS transitions for progress bars

As a newcomer to the world of ReactJS, I have been exploring the FB documentations and online tutorials to kickstart my test project. Within this project, I wanted to implement a progress bar that visually represents the user's progression through fi ...

Why does my Div seem to be ignoring the height inherited from the html or body elements?

Is there a way to make the landing-wrapper div expand to fill 100% of the screen on a landing page? Many suggestions advise setting the html/body height to 100%. I've already tried that, but it doesn't seem to be working. I'm using React and ...

What is the best way to make a CSS element move with Javascript?

Currently working on a JavaScript game where I am in need of a CSS object to replace the original JavaScript object. Specifically, I want my "sword" CSS object to move along with my player object when it is Unsheathead. All the examples I find only show wh ...