I have table with width: 100% and an element in that table with width: 40em; max-width: 100%, but the element is still stretching the table when th
You should use table-layout: fixed for the table element to get the From the MDN: The fixed value: WORKING DEMO.max-width properties of 's descendants to work.
table-layout CSS property defines the algorithm to be used to
layout the table cells, rows, and columns.
Table and column widths are set by the widths of table and col elements or by the width of the first row of cells. Cells in
subsequent rows do not affect column widths.table {
table-layout: fixed;
}