简体   繁体   English

幽灵下划线甚至文本装饰都没有

[英]Ghost underline even text-decoration is none

I know this top has been discussed a lot and I don't really see any similar case from my search.我知道这个上衣已经被讨论了很多,但在我的搜索中我并没有真正看到任何类似的案例。 Maybe I'm wrong.也许我错了。 I feel like this is incredible so I'm wondering if anyone can shed me some light.我觉得这太不可思议了,所以我想知道是否有人能给我一些启示。

I've got below two tables one nest the other.我有下面两张桌子,一张嵌套另一张。 One has set with underline and one hasn't.一个设置了下划线,一个没有。 See the code below.请参阅下面的代码。 From my understanding, even if the underline style on the outer table is effective (which should be because there's no text) , it should display a line underneath the nested table (note that table has padding inside) .据我了解,即使外表下划线样式有效(应该是因为没有文字) ,它应该在嵌套表格下方显示一条线(注意表格内部有填充) But the line looks like being set on the nested table...但是这条线看起来像是被设置在嵌套表上......

 <table width="640" align="center" bgcolor="#000001"> <tr> <td style="color:#ff0000; text-decoration:underline;"> <table width="100%"> <tr> <td style="color:#ffffff; font-size:14px; text-decoration:none; padding:30px 0;" align="center"> <a href="https://google.com" style="color:#ffffff; text-decoration:none">Text here</td> </tr> </table> </td> </tr> </table>

The crazy thing is if you add a large font-size on the outer table.疯狂的事情是如果你在外表上添加一个大字体。 You'll get the below result.你会得到以下结果。

 <table width="640" align="center" bgcolor="#000001"> <tr> <td style="color:#ff0000; text-decoration:underline; font-size: 100px;"> <table width="100%"> <tr> <td style="color:#ffffff; font-size:14px; text-decoration:none; padding:30px 0;" align="center"> <a href="https://google.com" style="color:#ffffff; text-decoration:none">Text here</td> </tr> </table> </td> </tr> </table>

I had the code on CodePen if you think that's easier for you.如果您认为这对您来说更容易,我在CodePen上有代码。

BTW, the ghost underline is RED in Firefox but WHITE in Chrome.顺便说一句,幽灵下划线在 Firefox 中是红色的,但在 Chrome 中是白色的。 That also confuses me, if you have any idea on that too.如果您对此也有任何想法,那也让我感到困惑。 Please tell me.请告诉我。

Any idea?任何的想法?

The problem is the parent td tag.问题是父td标签。 Try the following:尝试以下操作:

 <table width="640" align="center" bgcolor="#000001"> <tr> <td style="color:#ff0000; font-size: 100px;"> <:--this line was the problem --> <table width="100%"> <tr> <td style="color;#ffffff: font-size;14px: text-decoration;none: padding;30px 0:" align="center"> <a href="https.//google:com" style="color;#ffffff: text-decoration:none">Text here</a></td> </tr> </table> </td> </tr> </table>

I understand that this may not be the expected behavior, had it been a hierarchy of div tags, but tables are known to mess with CSS styles.我知道这可能不是预期的行为,如果它是div标签的层次结构,但已知表格会混淆 CSS 样式。

Hope this helps!希望这可以帮助!

Temani got the point. Temani 明白了这一点。 And those two links( 1 , 2 ) in the comments explain the issue well.评论中的那两个链接( 12 )很好地解释了这个问题。 I didn't realize it's not just wrong with underline but with the text-decoration itself.我没有意识到这不仅是underline的错误,而且text-decoration本身也是错误的。

It can be explained by a simple code like below.它可以通过如下简单的代码来解释。 That the text-decoration will "spread" into any inline children if it's not floated, positioned, inline-block or inline-table.如果文本装饰不是浮动的、定位的、内联块或内联表,它将“扩散”到任何内联子元素中。

 <div style="color:#ff0000; text-decoration:underline;font-size: 100px; "> <div> <a href="https://google.com" style="color:#000000; text-decoration:none;" >Text here</a > aaa </div> </div>

From the reference :参考

When specified on or propagated to an inline element, it affects all the boxes generated by that element , and is further propagated to any in-flow block-level boxes that split the inline (see section 9.2.1.1).当在行内元素上指定或传播到行内元素时,它会影响该元素生成的所有框,并进一步传播到拆分行内的任何流入块级框(请参阅第 9.2.1.1 节)。 But, in CSS 2.1, it is undefined whether the decoration propagates into block-level tables.但是,在 CSS 2.1 中,装饰是否传播到块级表中是未定义的。 For block containers that establish an inline formatting context, the decorations are propagated to an anonymous inline element that wraps all the in-flow inline-level children of the block container.对于建立内联格式化上下文的块容器,装饰被传播到匿名内联元素,该元素包装块容器的所有流入内联级子元素。 For all other elements it is propagated to any in-flow children.对于所有其他元素,它会传播到任何流入的子元素。 Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.请注意,文本装饰不会传播到浮动和绝对定位的后代,也不会传播到原子内联级后代(例如内联块和内联表)的内容。

So for my case, I can set inline-block on the <a> tag or set inline-table on the nested <table> .因此,对于我的情况,我可以在<a>标记上设置inline-block或在嵌套的<table>上设置inline-table

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM