Transparent text cut out of background

One way that works on most modern browsers is to use background: black; color: white; mix-blend-mode: multiply; for transparent text on a black background, or background: white; color: black; mix-blend-mode: screen; for transparent text on a white background. For this to work in chrome, you also need to set any background colour on the html … Read more

jQuery SVG, why can’t I addClass?

Edit 2016: read the next two answers. JQuery 3 fixes the underlying issue Vanilla JS: element.classList.add(‘newclass’) works in modern browsers JQuery (less than 3) can’t add a class to an SVG. .attr() works with SVG, so if you want to depend on jQuery: // Instead of .addClass(“newclass”) $(“#item”).attr(“class”, “oldclass newclass”); // Instead of .removeClass(“newclass”) $(“#item”).attr(“class”, … Read more

Fill SVG path element with a background-image

You can do it by making the background into a pattern: <defs> <pattern id=”img1″ patternUnits=”userSpaceOnUse” width=”100″ height=”100″> <image href=”wall.jpg” x=”0″ y=”0″ width=”100″ height=”100″ /> </pattern> </defs> Adjust the width and height according to your image, then reference it from the path like this: <path d=”M5,50 l0,100 l100,0 l0,-100 l-100,0 M215,100 a50,50 0 1 1 -100,0 … Read more

Convert SVG to image (JPEG, PNG, etc.) in the browser

The solution to convert SVG to blob URL and blob URL to png image const svg=`<svg version=”1.1″ baseProfile=”full” width=”300″ height=”200″ xmlns=”http://www.w3.org/2000/svg”> <rect width=”100%” height=”100%” fill=”red” /> <circle cx=”150″ cy=”100″ r=”80″ fill=”green” /> <text x=”150″ y=”125″ font-size=”60″ text-anchor=”middle” fill=”white”>SVG</text></svg>` svgToPng(svg,(imgData)=>{ const pngImage = document.createElement(‘img’); document.body.appendChild(pngImage); pngImage.src=imgData; }); function svgToPng(svg, callback) { const url = getSvgUrl(svg); svgUrlToPng(url, … Read more

How to change color of SVG image using CSS (jQuery SVG image replacement)?

Firstly, use an IMG tag in your HTML to embed an SVG graphic. I used Adobe Illustrator to make the graphic. <img id=”facebook-logo” class=”svg social-link” src=”https://stackoverflow.com/images/logo-facebook.svg”/> This is just like how you’d embed a normal image. Note that you need to set the IMG to have a class of svg. The ‘social-link’ class is just … Read more