Is it possible to have two tables with different columns but the same height in HTML and CSS?

I am facing an issue with two tables that are floated:left to appear next to each other. I want to make table 2 the same height as table 1, so that the yellow background extends down to the bottom of table 1. Here is the current setup:

https://i.sstatic.net/iiycK.png

What I want it to look like:

https://i.sstatic.net/sVupi.png

I prefer not to set fixed pixel heights, as I need it to display consistently across different monitors and mobile devices.

Edit: I have decided to give the last row a longer height based on the answers provided. Thank you for your help.

Answer №1

To determine the number of rows in a table, this JavaScript code snippet can be used within a tag:

var totalRows = document.getElementById("myTable").rows.length;

Here, "myTable" refers to the id attribute of the left table.

Next, you can match the row count of the second table with the variable x obtained earlier:

var currentRows = document.getElementById("mySecondTable").rows.length;

The difference between x and y will indicate how many new rows need to be added to the second table:

var numRowsToAdd =  totalRows - currentRows;

for(var i = 0; i < numRowsToAdd; i++) {
  var secondTable = document.getElementById("mySecondTable");
  var newRow = document.createElement('tr');
  //Customize attributes of the newly created row, such as background-color.

 secondTable.appendChild(newRow);
}

Answer №2

You can give the parent div the class .row-eq-height:

CSS:

.row-eq-height {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

See it in action here

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

Displaying the Indian Rupee symbol in PHP

I'm attempting to show the Indian rupee symbol using HTML code ₹ The HTML code is being echoed in PHP and everything seems to be working fine, except that the rupee symbol is not showing up. I've tested using other currency symbols and the ...

Building a Horizontal Line Component in ReactJS

Looking for help with my login page design. I have two login buttons - one for regular login and one for Google login. I want to add a stylish horizontal line with the word "OR" between the buttons, similar to the image in the link provided. https://i.sst ...

How can one transform personalized HTML into a PDF document?

I attempted to send a customized HTML (+CSS) as a PDF, but the resulting PDF sent is only in black and white. I would appreciate any assistance with this issue. Thank you :) Below is the function that I used: function sendEmails() { var data = getBo ...

Transition smoothly between sections using fullPage.js with clipping path effects

I am looking to create a unique clipping animation utilizing SVG clipping path. The animation should hide the first section while revealing the second section in a smooth transition using fullPage.js. This idea is somewhat similar to the question discusse ...

In CSS, the color inheritance applies when a link is contained within a block of text

Inside the container, the text color is white. However, the link inside the text appears blue instead of white. I have implemented material ui styles for this issue. Although I have tried using the !important tag, it still doesn't work. ...

What is the best way to determine the currently active component in Angular 5?

I am currently working on creating a settings button that will dynamically change its content based on the component that the user is viewing. I am unsure of the best practice for accomplishing this task. My initial thought is to utilize an Angular directi ...

The functionality of HTML labels may be limited when used in conjunction with AJAX

I am using Ajax to load an HTML page and encountering a problem with the label not working properly when associated with a checkbox. Here is the data: <input type="checkbox" name="dis_net" id="dis_net" value="1" /> <label for="dis_net">Test< ...

The loop in MVC is not functioning properly when dealing with various MapRoutes

I am new to MVC and have a good understanding of C#. While experimenting with MVC in Visual Studio, I encountered an issue that is puzzling me. I am struggling to identify the cause of this error. My goal is to print a variable n number of times. It works ...

Conditional rendering of Materialize navbar links

I am currently working with React Materialize and React Router Dom. My goal is to display navlinks only to authenticated users using conditional rendering. However, when I implement it as shown below, the navlinks are displayed vertically instead of hori ...

Unable to utilize CSS filter property in Internet Explorer 10

I am trying to add a CSS filter to the body tag. I have applied the following CSS rules and created a JS Fiddle with the styles - JS fiddle with CSS styles The filter works well in Chrome, Firefox, and Opera, but it doesn't seem to apply in Internet ...

Position the dropdown items of the navbar side by side

I am currently struggling to align my Bootstrap 4 dropdown items side by side as shown below: https://i.sstatic.net/i3pP0.png The desired layout involves having Item 1 and Item 2 as dropdown options when hovering over the first Test item. I attempted to ...

Ways to gather all the elements on each page

Currently engrossed in a web scraping endeavor for a car website utilizing Selenium. One potential roadblock I've encountered is that the code seems to only iterate over the initial car element on the page, instead of going through the entirety of ava ...

What could be causing Ajax's html() function to create a loop that never ends?

Is there a way to incorporate an animation during the database operation and update the table content in the HTML document once the operation is completed? <script> var jobj = new Object(); jobj.uid = <?php echo "'".$_SESSION['user_ ...

While attempting to access a form response in Java, I have encountered an issue where the content does not load properly due to the delay in loading. This causes Java to retrieve incorrect information

Is there a way to delay the page load until the response is fully loaded? url = new URL("http://somesite.com/sompage.jsp?somefield=something"); URLConnection conn = url.openConnection(); BufferedReader br = new Buffe ...

When using the scrollHeight property of an iframe, it actually returns the height of the iframe

I'm having trouble obtaining the correct height of a page within an iFrame using scrollHeight. It seems to only return the height of the iframe itself, not the content inside. Despite trying various methods like scrollHeight, offsetHeight, and style. ...

Adapting the Homepage Based on User Authentication

Currently, I am working on a website where I am implementing a login feature. Once the user logs in successfully, they should be redirected to the index page and see something other than the login button. I have been using the following code for my implem ...

What is the best way to apply box shadow to a particular region using CSS?

I am looking to add a box shadow using CSS, but I only want it in a certain area of the box. https://i.sstatic.net/dcFZu.png In the screenshot above, you can see that I have a blue header on my website. I would like to add a shadow to this header, specifi ...

The dynamic page is causing JQuery to be triggered twice

Encountering an issue with my web page setup: The dynamic loading of html content from admin_agent_area.php into divs (#adminarea) in index.php is causing a problem. This action occurs when clicking the link "#adduser" and a jquery function manages the loa ...

What is the best way to place a select tag within a container that is nested inside an echo statement?

I'm struggling with integrating this code snippet echo "<select name='edu'>"; Can anyone guide me on how to nest this dropdown menu within a <div> or <p> tag for better positioning? I aim to place it in a container that o ...

Looking for assistance with CSS to properly align a dozen items

UPDATE: See the current layout in this JFiddle based on feedback received from others, still a few tweaks needed. In my setup, there are 12 divs housed within one container div. These 12 divs consist of 6 text components and 6 corresponding input fields. ...