0

Is it possible to have text with a background image and inner shadow at the same time?

div{   
    position:fixed;
    z-index: 2;
    color: white;  /* Fallback: assume this color ON TOP of image */
    background: url('https://placekitten.com/g/500/500') repeat;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 100px;
    font-weight: 800;
    text-transform: uppercase; 
    text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset; 
}
<div>
  CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

1 Answer 1

1

With the CSS filter property you can add shadows that contour any shape:

div{   
    position:fixed;
    z-index: 2;
    color: white;  /* Fallback: assume this color ON TOP of image */
    background: url('https://placekitten.com/g/500/500') repeat;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 100px;
    font-weight: 800;
    text-transform: uppercase; 
    text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset; 
    filter: drop-shadow( 10px 10px 10px #888 );
}
<div>
  CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

All major browsers now support basic filter! http://caniuse.com/#feat=css-filters

For Inset Shadows

Inset shadows require some trickery.

My approach was to add another div directly on top of your first one with transparent text opacity. Then we use a text shadow hack to make it appear inset.

.regular {
    position:fixed;
    z-index: -1
    color: white;  /* Fallback: assume this color ON TOP of image */
    background: url('https://placekitten.com/g/500/500') repeat;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 100px;
    font-weight: 800;
    text-transform: uppercase; 
    text-shadow: 2px 3px 8px rgba(59, 37, 17, 0.35) inset; 
}
.overlay {
    position:fixed;
    z-index: 10;
    color: transparent;
    font-size: 100px;
    font-weight: 800;
    text-transform: uppercase; 
    text-shadow: 2px 2px 3px rgba(255,255,255,0.5);
    -webkit-background-clip: text;
       -moz-background-clip: text;
            background-clip: text;
}
<div class="regular">
  CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>
<div class="overlay">
  CAN I HAVE AN IMAGE AND INNER SHADOW?
</div>

Sign up to request clarification or add additional context in comments.

2 Comments

What about an inner shadow?
@Benneb10 Sorry, heh... I didn't quite see the inset part of your question at first. I've updated my answer and through some CSS hackery managed to make it inset. Had to use hacks becayse filter unfortunately doesn't have an inset property.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.