I'll try to explain my question with images. Here we go.
1 - This image shows the text masking an image, so far so good, I can do with the following code:
font-size: 120px;
background: url(image-to-be-masked.jpg) repeat 0 0, white;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
2 - This other image, the text creates the opposite effect, leaving transparent only the text area. This is what I want:
Has anyone tried it?
[sorry i misread this. I tried out opposite, think :P] I think you can do it by using background-clip.
check here (please try in chrome or add vendor prefixes). you can check demo page form chris.
I don't think CSS can do that. But you can hack it together using three different nested elements:
background-clip:text;
like on your first example.This works, but is a little cumbersome, as you'll have to compensate the masks background-position to achieve the desired effect. Here is an example: http://jsfiddle.net/dzkTE/.
I've managed to achieve this with a couple of different methods. See my answer here: https://stackoverflow.com/a/32476482/2315496
See Below:
There are three ways to what you're looking for in HTML/CSS/JavaScript, some a little more hacky than others.
<canvas>
to draw your shape and type, and setctx.globalCompositeOperation="xor";
wherectx
is your canvas context.mix-blend-mode: screen
and set the colour of the text to black.-webkit-text-fill-color:transparent
and-webkit-background-clip:text
to reveal a copy of the background behind it. This one requires some alignment of the background copy to match the 'original' background.None of these are likely to work that well cross browser, and I haven't tested them!