Is there any way to make a transparent text cut out of a background effect like the one in the following image, with CSS?
It would be sad to lose all precious SEO because of images replacing text.
I first thought of shadows but I can't figure anything out...
The image is the site background, an absolute positioned <img>
tag
You can use an inverted / negative / reverse font and apply it with the
font-face="…"
CSS rule. You might have to play with letter spacing to avoid small white gaps between letters.If you do not require a specific font, it's simple. Download a likeable one, for example from this collection of inverted fonts.
If you require a specific font (say, "Open Sans"), it's difficult. You have to convert your existing font into an inverted version. This is possible manually with Font Creator, FontForge etc., but of course we want an automated solution. I could not find instructions for that yet, but some hints:
One way that works on most modern browsers (except ie, edge), although only with a black background, is to use
in your text element and then put whatever background you want behind that. Multiply basically maps the 0-255 color code to 0-1 and then multiplies that by whatever is behind it, so black stays black and white multiplies by 1 and effectively becomes transparent. http://codepen.io/nic_klaassen/full/adKqWX/
Although this is possible with CSS, a better approach would be to use an inline SVG with SVG masking. This approach has some advantages over CSS :
CodePen Demo : SVG text mask
If you aim on making the text selectable and searchable, you need to include it outside the
<defs>
tag. The following example shows a way to do that keeping the transparent text with the<use>
tag:It is possible, but so far only with Webkit based browsers (Chrome, Safari, Rockmelt, anything based on the Chromium project.)
The trick is to have an element within the white one that has the same background as the body, then use
-webkit- background-clip: text;
on the inner element which basically means "don't extend the background beyond the text" and use transparent text.http://jsfiddle.net/BWRsA/
just put that css
You can use myadzel's Patternizer jQuery plugin to achieve this effect across browsers. At this time, there is no cross-browser way to do this with just CSS.
You use Patternizer by adding
class="background-clip"
to HTML elements where you want the text to be painted as an image pattern, and specify the image in an additionaldata-pattern="…"
attribute. See the source of the demo. Patternizer will create an SVG image with pattern-filled text and underlay it to the transparently rendered HTML element.If, as in the question's example image, the text fill pattern should be a part of a background image extending beyond the "patternized" element, I see two options (untested, my favourite first):