I need to set a max-height
rule for a table's tbody
with overflow
set to auto
, so that a scrollbar only appears when the table exceeds a certain height.
Is there a way to restrict the height of a tbody
element within a table
in this manner?
The table I am focusing on is dynamically added within a cell of a larger table, which is enclosed in a Bootstrap panel container. Attempting to do this with the provided code did not yield the desired results:
html = "";
html += "<p>";
html += "<table class=\"sortable target_detail_sortable\" style=\"width:100%;\" id=\"my_div_table\">";
html += "<thead>";
// fill in header cells
html += "</thead>";
html += "<tbody style=\"max-height:300px; overflow:auto;\">";
// fill in body cells
html += "</tbody>";
html += "</table>";
html += "</p>";
$("#my_div").html(html);
I would greatly appreciate any helpful suggestions, thank you!