Below is a way to do this, which will work.
https://jsfiddle.net/ocp36uLb/32/
table { border-collapse: collapse; width: 100%; } td { width: 50%; padding-bottom: 50%; display: inline-block; }
By setting the margins to be the same as the width, we create a square that maintains its aspect ratio when resizing. We also need to use display: inline-block; to override the default display: table-cell; which will make the cell expandable to fit it. border-collapse: collapse; also important as it overrides any visualization of the bounds associated with the table.
However, this method may be a pixel in some sizes due to the way tables are displayed. It works great for divs (which you could use instead, I suppose) - even without defining a border limit.
Another way that works great for tables is to use vw units . A bit trickier as they take the size from the viewport, so you will need to consider how much of the viewport has the total size of the table. 1vw is 1% of the viewing area. You will see from the link that this is perfect.
table { width: 100%; border-collapse: collapse; } td { height: 15vw; width: 15vw; display: inline-block; }
vw units are not very well supported (old IE, some mobile browsers), so itβs probably worth using a reserve.
source share