admin管理员组文章数量:1418061
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 ;)
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 ;)
-
Interesting. Replacing the
div
pletely does work - jsfiddle/4yj7U/2. I'm curious to know what's the reason behind this behaviour. – pimvdb Commented Sep 2, 2011 at 10:02 -
Changing CSS
style.display
for div#ahah frominline-block
toinline
workarounds this bug for Chrome. It's important for you to haveinline-block
display value for div#ahah? – Andrew D. Commented Sep 2, 2011 at 10:19 - Please consider filling a bug in Webkit's bugzilla. – duri Commented Sep 2, 2011 at 10:25
- @Andrew: yes, it's needed for the layout I use (it's way more plex than the test case ;) ) – Py. Commented Sep 2, 2011 at 10:37
- This is a fix that only works the first time: jsfiddle/thirtydot/4yj7U/7 – thirtydot Commented Sep 2, 2011 at 11:19
3 Answers
Reset to default 2Way what I found: remove all childs from overall DIV, and then append all except BR's:
function removeBr(){
var ahah=document.getElementById("ahah");
var childs=[],child;
while(child=ahah.firstChild) {
if(!child.tagName||child.tagName.toLowerCase()!=='br')
childs.push(child);
ahah.removeChild(child);
}
for(var i=0;i<childs.length;i++)
ahah.appendChild(childs[i]);
}
http://jsfiddle/4yj7U/4/
Other variant:
function removeBr(){
var node=$("#ahah")[0];
node.style.display='inline';
$("#ahah").children("br").remove();
setTimeout(function(){node.style.display='';},0);
}
As a work around, you could set the style to display: block
when you want them on individual lines and revert to inline-block
when you want them to be friends.
I have created a JS Fiddle example
Which demonstrates this fix:
function addBr(){
$('span').css({ display: 'block'});
}
function removeBr(){
$('span').css({ display: 'inline-block'});
}
$("#add").click(addBr);
$("#remove").click(removeBr);
This bug still exists, so here's another workaround: http://jsfiddle/4yj7U/19/
$("span").css('display', 'none');
setTimeout(function(){
$('span').css('display', 'inline-block');
}, 0);
This makes Chrome re-render the spans and displays them properly.
本文标签: javascriptChromeWebkit inlineblock refresh problemStack Overflow
版权声明:本文标题:javascript - ChromeWebkit inline-block refresh problem - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745251279a2649835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论