使用CSS剪切文本 [英] Cut-out text with CSS

查看:114
本文介绍了使用CSS剪切文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为CSS中的按钮创建悬停效果。

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

基本上,文本应该剪切其父元素,使其透明到网站背景。

我会用渐变来做条纹,但我的问题是为字体添加透明度。

我看了一下background-clip,但是这样做与我试图实现的相反,使事情的方式更复杂。
有一个简单的方法来实现这种效果吗?我不介意使用JS,但如果可能的话没有jQuery。

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.

推荐答案

你可以得到这样的东西:
http://codepen.io/gc-nomade/pen/Dqcio /

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;
}

和标记:

    <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>

使用CSS,您甚至可以添加透明边框和半径以使其看起来更加明亮http://codepen.io/gc-nomade/pen/wsfvg/

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

这篇关于使用CSS剪切文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆