I need to introduce the following built-in SVG filter into my HTML5 document:
<svg> <defs> <filter id="grayscale"> <feColorMatrix type="matrix" values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"> </filter> </defs> </svg>
I tried to place it outside of the <html> tags, but that didn't work. It leaves a large empty space at the beginning or end of the displayed page, depending on where I put it.
I tried placing it at the <head> or the beginning of the <body> , but this also leaves a lot of blank space at the beginning of the displayed document.
display: none; setting display: none; The SVG object will interfere with the filter.
I also tried setting the <svg> width and height to zero, but this only works if I set the CSS for the svg objects in display: block; .
For instance:
<!DOCTYPE html> <html> <head> ... <svg> ... </svg> </head> ... </html>
My temporary fix is ββcurrently using css to try to hide it:
svg { height: 0; position: absolute; }
How to prevent an SVG object from interfering with my HTML layout (without using this css trick)?
JsFiddle example
source share