8

How do I get table cells to be the same height? Check out http://thomaswd.com/organizer/dashboard and click on calendar. You will see that the table cells have different heights. I have 2 rows on the top of the table that is fixed height, and my table height is 100%. I don't want a specified pixel height, because that will not work when the browser is resized. How do I do this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Thomas Lai
  • 875
  • 4
  • 11
  • 19

4 Answers4

6

Looks like what you want is for the tallest cell's height to propagate across the row.

You can do this with javascript:

var eq_el_height = function(els, min_or_max) {

    els.each(function() {
        $(this).height('auto');
    });

    var m = $(els[0]).height();

    els.each(function() {
        var h = $(this).height();

        if (min_or_max === "max") {
            m = h > m ? h : m;
        } else {
            m = h < m ? h : m;
        }
    });

    els.each(function() {
        $(this).height(m);
    });
};

Pass your table cells into the function like this:

        $(#fixedheight tr').each(function(){
            eq_el_height($(this).find('td'), "max");
        });
sanon
  • 6,403
  • 2
  • 21
  • 26
3

To get the table cells to have equal height I used Google Chrome and inspected one of the days on the calendar by right-clicking on the day and selecting 'Inspect Element'. Then I changed the styling of 'calendar-day' like so:

/* shared */
td.calendar-day, td.calendar-day-np {  
    border-bottom:1px solid #999; 
    border-right:1px solid #999; 
    height: 10%;
}

Just specify in style.css what you would like the height to be.

Jesus Noland
  • 197
  • 2
  • 11
2

Another solution could be:

var maxHeight = null;
$('#tableId tr').each(function() {
    var thisHeight = $(this).height();
    if(maxHeight == null || thisHeight > maxHeight) maxHeight = thisHeight;
}).height(maxHeight);
Erick Lanford Xenes
  • 1,467
  • 2
  • 20
  • 34
1

From: How can I force all rows in a table to have the same height

<html>
    <head>
        <style type="text/css">
            #fixedheight {
                table-layout: fixed;
            }

            #fixedheight td {
                width: 25%;
            }

            #fixedheight td div {
                height: 20px;
                overflow: hidden;
            }
        </style>
    </head>
    <body>
        <table id="fixedheight">
            <tbody>
            <tr>
                <td><div>content</div></td>
                <td><div>lots of content that should spend way more time wrapping down than it should if I were just to have a short bit of stuff, that would be invaded by zombies and the such</div></td>
                <td><div>more content</div></td>
                <td><div>small content</div></td>
                <td><div>enough already</div></td>
            </tr>
            </tbody>
        </table>
    </body>
</html>
Community
  • 1
  • 1
Henry Quekett
  • 429
  • 1
  • 7
  • 16