html文字遮罩的用途,使用HTML5和CSS3制作遮罩文字特效

遮罩文字特效指的是文字下面的图片被文字层遮挡住,图片只在文字中显示。这种效果使用photoshop来制作是非常简单的。现在,Webkit内核的浏览器支持CSS3的background-clip属性,它能够完成和photoshop相同的文字遮罩效果。

另外,还可以使用CSS3 mask-image 属性来完成同样的效果。

制作这个特效的基本HTML结构如下:

THE LION

King of the Jungle

在CSS代码中,将使用background-clip属性来剪裁文本。对两个div元素分别使用不同的背景图片,并通过webkit-text-fill-color属性设置为transparent,确保文字的填充色为透明色。

#clipped-title1 {

background: url(../images/lion.jpg) no-repeat center center;

background-size: cover;

color: #fff;

-webkit-text-fill-color: transparent;

-webkit-background-clip: text;

}

#clipped-title2 {

background: url(../images/jungle.jpg)no-repeat top center;

background-size: cover;

color: #fff;

-webkit-text-fill-color: transparent;

-webkit-background-clip: text;

cursor: pointer;

}

#clipped-title1 h1 {

font-size: 200px;

font-family: Anton, sans-serif;

text-align: center;

-webkit-transition: text-shadow 1s ease;

text-shadow: 0 0 1px rgba(0,0,0,.1);

margin: 0;

padding: 0;

}

#clipped-title2 h1 {

font-size: 110px;

font-family: Pacifico, sans-serif;

text-align: center;

-webkit-transition: text-shadow 1s ease;

text-shadow: 0 0 1px rgba(0,0,0,.1);

margin-top: -75px;

padding: 0;

}

使用Webkit Mask-Image属性创建遮罩文字

遮罩文字特效

Mask-Image属性创建遮罩文字特效

通过-webkit-mask-image属性,你可以在文字上设置图片,制作这个特效的HTML结构如下:

CERTIFIED ROUGH
TEXTURED TEXT

在CSS中,简单的设置一些基本的CSS样式,然后通过-webkit-mask-image属性来为文字设置图片纹理。

#masked-image {

font-family: Oswald, sans-serif;

font-size: 100px;

color: #fff;

text-transform: uppercase;

border: 14px solid #fff;

border-radius: .2em;

text-align: center;

margin: 0;

display: block;

-webkit-mask-image: url(../images/rough-texture.png);

-webkit-transform: rotate(-4deg);

-moz-mask-image: url(../images/rough-texture.png);

-moz-transform: rotate(-4deg);

-o-mask-image: url(../images/rough-texture.png);

-o-transform: rotate(-4deg);

mask-image: url(../images/rough-texture.png);

transform: rotate(-4deg);

}

完整源码下载地址

https://tc5.us/file/21793581-403021450

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值