Created
January 31, 2018 14:06
-
-
Save mbutsko/271ecd85552f8222988f9552db26b8fb to your computer and use it in GitHub Desktop.
Table Width Calculation is Weird
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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