Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut-out text with CSS

I try to create a hover effect for a button in CSS.
How it should look like finished

Basically text should be 'cut out' of its parent element, making it see-through to the sites background.
I'd do the stripes with a gradient, but my problem is to add transparency to the font.
I looked at background-clip, but that would do the opposite of what I try to achieve, and would make things way more complicated. Is there an easy way to accomplish this effect? I don't mind using JS, but no jQuery if possible.

like image 970
Moritz Friedrich Avatar asked Mar 23 '14 15:03

Moritz Friedrich


2 Answers

to follow my comment and links within , using svg , you can get this kind of things : http://codepen.io/gc-nomade/pen/Dqcio/

svg {
  position:absolute;
  background:repeating-linear-gradient(-45deg,
    transparent,
    transparent 5px,
    black 5px,
    black 10px
    );
  width:600px;
  height:300px;
  box-sizing:border-box;
  background-clip: content-box; 
  padding:60px 70px;
}
text {
  font-size:8em;
  fill:url(#textpattern);
  stroke: white;
  border:solid;
  }
div {
  position:relative;
  width:600px;
  margin:auto;
}

and markup :

    <div>
  <svg>
    <defs>
      <pattern id="textpattern" patternUnits="userSpaceOnUse" width="600" height="300" >
        <image xlink:href="http://lorempixel.com/600/300/nature/9" width="600" height="300"  x="-70px" y="-60px"/>
      </pattern>
    </defs>
    <text  y="120px" x="140px">test </text>
  </svg>
  <img src="http://lorempixel.com/600/300/nature/9" />
</div>

With CSS , you can even add transparent borders and radius to make it look weirder http://codepen.io/gc-nomade/pen/wsfvg/

like image 122
G-Cyrillus Avatar answered Oct 05 '22 12:10

G-Cyrillus


In my example below, I'm using CSS mix-blend-mode with a blend mode of difference.

@import url(http://fonts.googleapis.com/css?family=Raleway:900,600,500,800,700);
* {
  box-sizing: border-box;
}
body {
  font-family: 'Raleway', sans-serif;
  background-color: white;
}
div {
  position: relative;
}
img {
  width:100%;
}
h1 {
  color: #000;
  background-color: #9c9c9c;
  padding: .5em 1em;
  position: absolute;
  bottom: 0;
  width: 100%;
  font-size: 10vw;
  font-weight: 900;
  text-transform: uppercase;
  mix-blend-mode: difference;
}
<div>
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9674/isolation-destination.jpg" alt="" />
  <h1>Let the sun shine!</h1>
</div>

View on CodePen
View my blog post on compositing and blending

like image 28
André Mata Avatar answered Oct 05 '22 14:10

André Mata