I came across some strange cases of positioning problems when loading CSS lazily in Chrome, for example. the positioning of some elements (absolute, relative and cascading) is sometimes disabled by a huge margin.
Basically, what I am doing does not take into account the standard loading of the stylesheet using the link-tag and instead places the spanholder tag in order to have an easy way to get the URL later at the end of the body-Tag. After the DOM has fully loaded, I will replace the span-tag with the generated link-tag as follows:
loadCSS: function() { var el = jQuery('.is_css'); if(!el.length) return; // Build link element var linkEl = jQuery('<link />').attr({ media: 'all', type: 'text/css', rel: 'stylesheet', href: el.data('src') }); el.replaceWith(linkEl); }
I can verify that the CSS is fully loaded, as most of the elements look exactly the same as if I inserted the CSS directly into the head-tag. I assume that Chrome does not correctly calculate positions in some cases for absolute or relative positioned elements when CSS loads after loading the DOM.
I would like to provide you with HTML / CSS snippets, unfortunately, it goes out of scope to isolate falsely rendered elements. So instead, I ask if anyone is facing similar issues that might cause this kind of behavior. Perhaps there are some general tips on how to fix such problems.
Yours faithfully
javascript jquery html css google-chrome
Sutuma
source share