firefox - SVG in css pseudo-class does not alway appear on print page -
i creating stylesheet print media includes inline svg content of element's pseudo-class (i.e., ::before, ::after).
when testing in chrome, seems work fine, when page first loaded in firefox , safari, svg element not appear in print preview. appears on subsequent attempts.
i not sure going on, if had guess, conjecture be: when page hasn't been cached there latency rendering pseudo-element happening concurrently browser creating print page.
i curious know why happening, , if there solution svg pseudo-element can used reliably.
here stripped down code example. please see if can reproduce issue:
var button = document.queryselector('button'); button.addeventlistener('click', function () { window.print(); }); div { text-align: center; } button { margin: 2em; padding: 1em 2em; } @media print { button { display: none; } div::before { content: 'pseudo-elements'; font-weight: bold; margin-top: 1em; } div::after { position: relative; display: block; margin-top: 1em; content: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><circle cx='50' cy='50' r='50' /></svg>"); } } <div> <button> print </button> </div>
i can repro.
it seems bug loading of svg, guess same image.
one workaround load outside of @print rules display: none :
var button = document.queryselector('button'); button.addeventlistener('click', function() { window.print(); }); div { text-align: center; } button { margin: 2em; padding: 1em 2em; } div::after { display: none; content: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><circle cx='50' cy='50' r='50' /></svg>"); } @media print { button { display: none; } div::before { content: 'pseudo-elements'; font-weight: bold; margin-top: 1em; } div::after { opacity: 1; position: relative; display: block; margin-top: 1em; } } <div> <button> print </button> </div> an other 1 preload via js before hand.
Comments
Post a Comment