Skip to content

Instantly share code, notes, and snippets.

@mbutsko
Created January 31, 2018 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbutsko/271ecd85552f8222988f9552db26b8fb to your computer and use it in GitHub Desktop.
Save mbutsko/271ecd85552f8222988f9552db26b8fb to your computer and use it in GitHub Desktop.
Table Width Calculation is Weird
<html>
<head>
<style>
table {
width: 100%;
}
th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<tr>
<th>One</th>
<th>Two</th>
<th>Three</th>
<th>Four</th>
</tr>
<tr>
<td>Width: </td>
<td>Width: </td>
<td>Longer width: </td>
<td>Width: </td>
</tr>
</table>
<script>
(function() {
document.querySelectorAll('td').forEach((el) => {
el.innerText += el.getBoundingClientRect().width
});
}());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment