Chrome/Webkit内联块刷新问题
我发现的问题如下:
情况:我的整体 div 具有 inline-block
显示。其中有两个元素也具有 inline-block
显示。
然后我在两个元素之间添加(感谢 JavaScript)
。第二个转到下一行,这是正常行为。
错误部分:然后删除
(再次使用JavaScript)并且...显示不会改变。看来整体div的box没有重新计算。最后,我有两个相似的标记,但它们的显示方式不同(这有点问题,不是吗)。
它在 Firefox 上运行良好(它似乎是基于 webkit 的,因为 Android 浏览器的行为方式相同)。所以我的问题是,是否有一种不使用会改变 DOM 的方法的解决方法?使用的库是 jQuery。
测试用例此处。
编辑:按照duri的建议,我在webkit bugzilla中填写了一份错误报告,它是这里。但我仍在寻找解决方法 ;)
The problem I found is the following:
Situation: I have overall div that has a inline-block
display. Inside it are two element that have an inline-block
display as well.
Then I add (thanks to JavaScript) a <br/>
between the two elements. The second goes to the next line, which is the normal behavior.
Buggy part: The <br/>
is then removed (JavaScript again) and... the display doesn't change. It appears that the box of the overall div is not recalculated. In the end I have two similar markup that doesn't appear the same way (which is a bit problematic, isn't it).
It works fine on Firefox (it appears to be webkit based as the Android browser behave the same way). So my question is, is there a workaround that doesn't use methods that will alter the DOM? The library used is jQuery.
A test case here.
EDIT: As suggested by duri, I filled a bug report in webkit bugzilla, it's here. But I'm still looking for a workaround ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现的方式:从整个 DIV 中删除所有子项,然后附加除 BR 之外的所有子项:
http://jsfiddle.net /4yj7U/4/
其他变体:
Way what I found: remove all childs from overall DIV, and then append all except BR's:
http://jsfiddle.net/4yj7U/4/
Other variant:
作为解决方法,当您希望它们位于单独的行上时,您可以将样式设置为
display: block
,而当您希望它们成为朋友时,可以将样式恢复为inline-block
。我创建了一个 JS Fiddle 示例,
它演示了此修复:
As a work around, you could set the style to
display: block
when you want them on individual lines and revert toinline-block
when you want them to be friends.I have created a JS Fiddle example
Which demonstrates this fix:
这个错误仍然存在,所以这里有另一个解决方法:http://jsfiddle.net/4yj7U/19/
这使得 Chrome 重新渲染跨度并正确显示它们。
This bug still exists, so here's another workaround: http://jsfiddle.net/4yj7U/19/
This makes Chrome re-render the spans and displays them properly.