简体   繁体   English

HTML仅在Firefox上呈现不同

[英]HTML Different rendering on Firefox only

I've found something which seems to be wrong as HTML rendering, from Firefox only (actually Firefox version 27). 我发现仅在Firefox(实际上是Firefox版本27)中,HTML渲染似乎有问题。

Chrome, Safari, Opera, Internet Explorer and even IE8* render this html correctly : http://jsfiddle.net/Totjoss/eMB69/4/ Chrome,Safari,Opera,Internet Explorer甚至IE8 *均可正确呈现此html: http : //jsfiddle.net/Totjoss/eMB69/4/

* even if IE8 is wrong elsewhere. * 即使IE8在其他地方也出错。

As written in this sample, the TEST and TEST2 must be anchored to the blue area, just like this Chrome example rendering : 如本示例中所述,必须将TESTTEST2锚定到蓝色区域,就像这个Chrome示例渲染一样: Chrome渲染-正确的版本 And Firefox does not place the TEST and TEST2 according to it correclty : Firefox不会根据其正确性放置TESTTEST2 Firefox渲染-错误版本

Plus those TEST and TEST2 must be hidden by the green area - as the blue one has overflow:hidden in its style. 另外,那些TESTTEST2必须被绿色区域隐藏-因为蓝色区域已overflow:hidden在其样式中。

It seems Firefox is doing it wrong when the parents are tabled displayed ( display:table and display:table-cell ). 当显示父display:table时,Firefox似乎做错了( display:tabledisplay:table-cell )。 See the JSFiddle to see the HTML structure. 请参阅JSFiddle以查看HTML结构。

So is it a bug that should be reported ? 那是应该报告的错误吗?

Though there is a solution to this : Just surround the blue area content with another div which is position:relative and it's fixed, but it's quite annoying and useless. 尽管有一个解决方案:只是将蓝色区域内容与另一个div position:relative ,该div position:relativeposition:relative ,并且是固定的,但是这很烦人且无用。

PS : Edited title. PS:标题已编辑。

I found this interesting to pick at, but also odd! 我发现这很有趣,但也很奇怪!

Perhaps not knowing the full reason to what you are trying to do. 也许不知道您要做什么的完整原因。 But making divs render like tables and then trying to make them render like divs again ( position relative et all ) , is just asking for cross browser/device trouble. 但是,使divstables一样呈现,然后尝试再次使它们像divs一样呈现( 相对位置等 ),只是在跨浏览器/设备出现麻烦。

I gave up searching for a CSS 'throw in ' to solve the problem ( there might be one ) - even if there was, does it not feel 'wrong' to you / 我放弃了寻找CSS“投入”来解决问题(可能有一个)的想法-即使有,对您来说也不觉得“错” /

Hard to give an answer here, and I think you have started to answer it too, so my answer would be. 在这里很难给出答案,我想您也已经开始回答它,所以我的答案应该是。

Separate Layout elements from content elements. 将布局元素与内容元素分开。

Whatever we are trying to do - trying to format content/text ( the vertical align benefits you are getting from table-cell perhaps ) should be done with wrappers inside your layout elements- just to be solid and safe. 无论我们要做什么-尝试格式化内容/文本(可能从table-cell获得垂直对齐的好处 )都应该在布局元素内部使用包装器-牢固可靠。

Sorry hope helps! 希望对不起! Maybe the css 'fix', will get posted 也许CSS的“修复”,将被张贴

TL;DR : change div#right to be position:absolute;height:100% and it will look like your non-firefox example. TL; DR :将div#right更改为position:absolute;height:100% ,它看起来像您的非Firefox示例。


In firefox's rendering of your example, div#test and div#test2 are way off to the left because their parent, div#right is styled as both display:table-cell and position:relative . 在您的示例的firefox渲染中, div#testdiv#test2向左移动,因为它们的父级div#right的样式都设置为display:table-cellposition:relative The problem is, 问题是,

The effect of position:relative on table-* elements is undefined. position:relativetable-*元素的影响是不确定的。
MDN MDN

So basically, webkit have chosen to do one thing and Gecko another. 因此,基本上,Webkit选择了做一件事,而Gecko选择了另一件事。 Neither is wrong according to the spec, because the spec does not define the right answer. 根据规范,这都没有错,因为规范没有定义正确的答案。

However, if you change to position:absolute the children will position themselves as you expect. 但是,如果您更改position:absolute ,孩子们将按照您的期望对自己进行定位。

More generally, I'd advise using flexbox if you are able to . 一般来说, 如果可以的话 ,我建议您使用flexbox It's much better suited to what I think you're trying to do. 它更适合我认为您要尝试的操作。

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

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