If I understood the question correctly, you can make use of the combination of -webkit-background-clip: text
and -webkit-text-fill-color: transparent
, but this is experimental feature and only work on webkit browsers and supposed to be supported on the soon to be released Firefox 49 (read the "text" row of the Browser Compatibility table), but for IE, so sorry.
CodePen 1
.. for -webkit-background-clip: text
part, currently, test with webkit browsers to see the effect
#test-div {
width: 800px;
height: 200px;
font-weight: bold;
font-size: 120px;
background: url('//lorempixel.com/800/200/sports/3/') no-repeat;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
<div id="test-div">Dummy Text</div>
Good news is as you mentioned in the question SVG would be great with much wider browser support (back to IE9), also the mask
element could contain multiple elements, shapes, text, paths all together. Beside it's possible to control the opacity of clipping by using different levels of gray-scale colors as alpha channel [CodePen example].
Using SVG mask
:
#theSVG #txtMask {
font-size: 120px;
font-weight: bold;
fill: white;
}
#theSVG #theIMG {
mask: url(#theMask);
}
<svg id="theSVG" viewBox="0 0 800 200" width="800" height="200">
<defs>
<mask id="theMask">
<text id="txtMask" x="0" y="50%">Dummy Text</text>
</mask>
</defs>
<image id="theIMG" xlink:href="http://lorempixel.com/800/200/sports/3/" x="0" y="0" height="200px" width="800px" />
</svg>
Updated Edit:
For a similar effect like the cut-off arrow inside the white rectangle in your question but with text instead, both CSS and SVG solutions:
CodePen 2
.. for -webkit-background-clip: text
part, currently, test with webkit browsers to see the effect
#test-div,
#test-div .txt {
width: 800px;
height: 200px;
font-weight: bold;
font-size: 60px;
position: relative;
background: url('//lorempixel.com/800/200/sports/3/') no-repeat;
}
#test-div .white-rect {
width: 80%;
height: 120px;
line-height: 120px;
position: relative;
top: 30px;
margin: 0 auto;
background-color: rgba(255, 255, 255, 0.9);
}
#test-div .txt {
box-sizing: border-box;
position: absolute;
left: 0;
top: 0;
padding-top: 50px;
text-align: center;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
/* SVG */
#theSVG #txtMask {
font-size: 60px;
font-weight: bold;
}
<h2>Using "background-clip:text"</h2>
<div id="test-div">
<div class="white-rect"></div>
<div class="txt">Dummy Text</div>
</div>
<hr>
<h2>Using SVG</h2>
<svg id="theSVG" viewBox="0 0 800 200" width="800" height="200">
<defs>
<mask id="theMask">
<rect x="10%" y="30" width="80%" height="120" fill="white" />
<text id="txtMask" x="30%" y="55%">Dummy Text</text>
</mask>
</defs>
<image xlink:href="http://lorempixel.com/800/200/sports/3/" x="0" y="0" height="200px" width="800px" />
<rect mask="url(#theMask)" x="10%" y="30" width="80%" height="120" fill="rgba(255,255,255,0.9)" />
</svg>