Cut-out text with CSS

浪尽此生 提交于 2019-12-17 16:58:38

问题


I try to create a hover effect for a button in CSS.

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.


回答1:


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/




回答2:


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




回答3:


Try using Photoshop to create text with just outline and no background color then save it in a .png format then place that text inside div and decorate this div with gradient. hope this helps in someway

Check Following Image Created in Photoshop.......



来源:https://stackoverflow.com/questions/22592885/cut-out-text-with-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!