简体   繁体   English

div 上的边框与 Chrome 中表头上的边框不对齐

[英]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 中)

Firefox 中的表头

But in Chrome the border is offset by one pixel:但是在 Chrome 中,边框偏移了一个像素:

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

<div> header 边框问题</div><div id="text_translate"><p>我刚刚创建了这个 div(用于浮动视口),其中还有一个 header div。 如下图所示,黑色背景(来自主框架)显示在黄色 header 周围。 我怎么看不到 header 周围的黑线。 我希望 header 背景的黄色渗入框架边框的黄色。</p><p> 这是我的两个 div 的 css 代码: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> #mydiv { position: absolute; z-index: 0; width: 250px; height: 250px; top: 300px; left: 100px; background-color: black; border: 2px solid #e8ff26; text-align: center; box-shadow: 2px 2px 4px #888888; } #mydivheader { padding: 3px; cursor: move; z-index: 0; /* border: 2px solid #e8ff26; */ background-color: #e8ff26; /* color: #e8ff26; */ }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="desktop"&gt; &lt;div id="mydiv"&gt; &lt;,-- Include a header DIV with the same name as the draggable DIV. followed by "header" --&gt; &lt;div id="mydivheader"&gt;iris - virtual learning device&lt;/div&gt; &lt;br&gt;&lt;br&gt; &lt;video width="247" autoplay loop muted&gt; &lt;source src="./videos/SCI6477_IRIS.mp4" type="video/mp4"&gt; &lt;/video&gt; &lt;!-- &lt;p&gt;Move This DIV&lt;/p&gt; --&gt; &lt;/div&gt;</pre></div></div><p></p><p> 其他 css 分区:</p><pre> /* if desktop */.mobile_device_380px { display: none; }.mobile_device_480px { display: none; } /* if mobile device max width 380px */ @media only screen and (max-device-width: 380px) {.mobile_device_380px{display: block;}.desktop {display: none;} } /* if mobile device max width 480px */ @media only screen and (max-device-width: 480px) {.mobile_device_480px{display: block;}.desktop {display: none;} }</pre><p> 这是问题-&gt;</p><p> <a href="https://i.stack.imgur.com/mqTwk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqTwk.png" alt="div的当前渲染"></a></p><p> 这应该是它的样子 -&gt; 当我拖动框架时,我得到了这个,有些地方显示正确的,其他地方显示错误的。 <a href="https://i.stack.imgur.com/i2aXw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i2aXw.png" alt="在此处输入图像描述"></a></p></div> - <div> header border issue

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将表格边框与div边框对齐 - How to align table border with div border 将水平边框线与 header div 对齐 - Align horizontal border line with header div 为什么在 div 区域中使用 display:table 时,border-top 不给出相同的边框宽度? - Why border-top doesn't give same border width while using display:table in div area? CSS中的上下边框无法在文本框内垂直对齐文本 <div> 标签 - Top and Bottom border in CSS doesn't align text vertically inside a <div> tag <div> header 边框问题</div><div id="text_translate"><p>我刚刚创建了这个 div(用于浮动视口),其中还有一个 header div。 如下图所示,黑色背景(来自主框架)显示在黄色 header 周围。 我怎么看不到 header 周围的黑线。 我希望 header 背景的黄色渗入框架边框的黄色。</p><p> 这是我的两个 div 的 css 代码: </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> #mydiv { position: absolute; z-index: 0; width: 250px; height: 250px; top: 300px; left: 100px; background-color: black; border: 2px solid #e8ff26; text-align: center; box-shadow: 2px 2px 4px #888888; } #mydivheader { padding: 3px; cursor: move; z-index: 0; /* border: 2px solid #e8ff26; */ background-color: #e8ff26; /* color: #e8ff26; */ }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;div class="desktop"&gt; &lt;div id="mydiv"&gt; &lt;,-- Include a header DIV with the same name as the draggable DIV. followed by "header" --&gt; &lt;div id="mydivheader"&gt;iris - virtual learning device&lt;/div&gt; &lt;br&gt;&lt;br&gt; &lt;video width="247" autoplay loop muted&gt; &lt;source src="./videos/SCI6477_IRIS.mp4" type="video/mp4"&gt; &lt;/video&gt; &lt;!-- &lt;p&gt;Move This DIV&lt;/p&gt; --&gt; &lt;/div&gt;</pre></div></div><p></p><p> 其他 css 分区:</p><pre> /* if desktop */.mobile_device_380px { display: none; }.mobile_device_480px { display: none; } /* if mobile device max width 380px */ @media only screen and (max-device-width: 380px) {.mobile_device_380px{display: block;}.desktop {display: none;} } /* if mobile device max width 480px */ @media only screen and (max-device-width: 480px) {.mobile_device_480px{display: block;}.desktop {display: none;} }</pre><p> 这是问题-&gt;</p><p> <a href="https://i.stack.imgur.com/mqTwk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mqTwk.png" alt="div的当前渲染"></a></p><p> 这应该是它的样子 -&gt; 当我拖动框架时,我得到了这个,有些地方显示正确的,其他地方显示错误的。 <a href="https://i.stack.imgur.com/i2aXw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i2aXw.png" alt="在此处输入图像描述"></a></p></div> - <div> header border issue 通过页眉与div边框 - border to the div through the Header 背景和边框 DIV 不会淡出 - Background and border DIV doesn't fade out 从表中删除`border`属性不会删除边框 - Removing `border` attribute from table doesn't remove the border 将div与图像边框对齐 - Align div to image-border div的表格边框间距 - Table border spacing with div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM