[英]Border on div doesn't align with border on table header in Chrome
I have a table with a header, and I'm trying to place a div next to it such that it appears to be an extension of the table header.我有一个带有标题的表格,我试图在它旁边放置一个 div,使其看起来像是表格标题的扩展。 This works fine in Firefox: (the X is in a div separate from the thead)
这在 Firefox 中工作正常:(X 位于与 thead 分开的 div 中)
But in Chrome the border is offset by one pixel:但是在 Chrome 中,边框偏移了一个像素:
When I inspect the elements in Chrome, both the thead and the div are the same height, so it's strange that their borders would end up in different places.当我在 Chrome 中检查元素时,thead 和 div 的高度相同,所以很奇怪它们的边框最终会在不同的地方。 If I add a 1px margin to the top of the div, the border lines up but it creates a one pixel tall gap at the top.
如果我在 div 的顶部添加 1px 边距,边框会对齐,但会在顶部创建一个 1 像素高的间隙。
Here's a codesandbox that shows what I'm dealing with.这是一个代码沙盒,显示了我正在处理的内容。 This example is using TailwindCSS .
此示例使用TailwindCSS 。 https://codesandbox.io/s/quirky-hooks-gf6cx View it in Firefox and Chrome to see the difference.
https://codesandbox.io/s/quirky-hooks-gf6cx在 Firefox 和 Chrome 中查看以查看差异。
Thanks for your help.谢谢你的帮助。
Chrome calculate the height of table with 1px more, it seems a bug. Chrome计算表的高度多1px,这似乎是一个错误。
To fix you can add the display block to tr https://codesandbox.io/s/modest-tu-muw2m要修复,您可以将显示块添加到 tr https://codesandbox.io/s/modest-tu-muw2m
EDIT:编辑:
You can create a div inside a th element to avoid bug: https://codesandbox.io/s/reverent-microservice-ltz40您可以在 th 元素内创建一个 div 以避免错误: https : //codesandbox.io/s/reverent-microservice-ltz40
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.