user3997246
user3997246

Reputation:

CSS Mask-image won't work

I am trying to mask image (with text shadow) using CSS property -webkit-mask-image.

I understand that I can use background-clip however I need to do this using only mask-image

property for some reason. However upon trying it out I was stack with some CSS codes.

here's my CSS code:

#masking h1, span.mask-text {
    font-size: 230px;
    font-family: 'Lilita One', sans-serif;
    text-align: center;
    margin: 0 auto;
    padding: 0;
    -webkit-text-fill-color:transparent;
    position:absolute;
    left: 100px;


}

#masking h1 {
    text-shadow: 3px 3px 0px #34495e;
    z-index:2;
}

span.mask-text {
       -webkit-mask-image: url('http://halloweenmaternitycostumes.com/wp-content/uploads/2014/11/paper.jpg') no-repeat center center;
   background-size: cover;
    z-index:5;
    -webkit-transition:all 0.7s ease;
   -moz-transition:all 0.7s ease;
     -o-transition:all 0.7s ease;
        transition:all 0.7s ease;

}

span.mask-text:hover{
cursor: pointer;
 -webkit-mask-image: ('http://halloweenmaternitycostumes.com/wp-content/uploads/2014/11/paper-hover.jpg') no-repeat center center;
   background-size: cover;
 z-index:5;

}
span.mask-text:after {
    content: 'Mask Text';
    text-transform: uppercase;
}

Here's an image what I am trying to do:

enter image description here

Here's the jsFiddle version: http://jsfiddle.net/cmtr3txu/2/

If you could show me the solution using jsFiddle that would be great.

Upvotes: 3

Views: 1877

Answers (1)

roman
roman

Reputation: 547

I updated your code here: http://jsfiddle.net/cajvgkxt/3/

To add a background to the text, do as follows... Note: background must come before clipping!

span{
    font-size: 50px;
    font-family: Helvetica, Arial;
  background: url(http://www-users.cs.umn.edu/~interran/texture/lic2.gif);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
<span>Text</span>

Your code does two things novel-- animation and text-shadow. For the text-shadow, I made sure that your span and h1 both had font-weight:bold (by default, one is bold and the other is not). For the animation, I left it up to you to customize. You'll need to change the easing and background position.

Upvotes: 7

Related Questions