0

I have two tables like so. These are floated:left to appear next to each other. I would like to have table 2 the same height as table 1. As in, the yellow background goes down to the bottom of table 1. Currently:

Table

Should look like:

enter image description here

I don't want to have to hard code pixels as it needs to display the same across different monitors and mobile devices.

Edit: I'll just give the last row a longer height. Thanks for your answers.

3
  • Can you share some HTML and CSS? Off the top of my head, you could make sure that both tables have the same number of entries. Commented Jul 28, 2016 at 1:16
  • Just a generic table. 6 <tr's> on left side, with 2 <td> in each. 3 <tr> on right, with 1 <td> in each. I'll try adding 3 extra <tr> on right side. EDIT:Adding extra <tr> does not work. Commented Jul 28, 2016 at 1:52
  • Can't you make them one table? Commented Jul 28, 2016 at 2:36

2 Answers 2

2

You can find out how many rows are in a table using this call (JavaScript, include it in a tag):

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

where "myTable" is the id of your left table.

Then set the number of rows in the second table to x by getting the current number of rows:

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

where "mySecondTable" is the id of your right table.

var numRowsToCreate = x - y;

for(i = 0; i < numRowsToCreate; i++) {
  var secondTable = document.getElementById("mySecondTable");
  var newRow = document.createElement('tr');
  //Set any attributes of the table row here, like background-color.

 secondTable.appendChild(newRow);
}
Sign up to request clarification or add additional context in comments.

1 Comment

There are always going to be a static amount of rows in table 1. Can i just add <tr> x amount of times to make the amount the same?
1

Add class .row-eq-height to parent div:

CSS:

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

DEMO

1 Comment

Looks like the best answer. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.