Inner text shadow with CSS

后端 未结 22 1352
情深已故
情深已故 2020-11-28 18:07

I am currently playing around with CSS3 and trying to achieve a text effect like this (the black blurry inner shadow):

22条回答
  •  温柔的废话
    2020-11-28 18:40

    More precise explanation of the CSS in kendo451's answer.

    There's another way to get a fancy-hacky inner shadow illusion,
    which I'll explain in three simple steps. Say we have this HTML:

    Get this

    and this CSS:

    h1 {
      color: black;
      background-color: #cc8100;
    }
    

    It's a good slogan

    Step 1

    Let's start by making the text transparent:

    h1 {
      color: transparent;
      background-color: #cc8100;
    }
    

    It's a box

    Step 2

    Now, we crop that background to the shape of the text:

    h1 {
      color: transparent;
      background-color: #cc8100;
      background-clip: text;
    }
    

    The background is the text!

    Step 3

    Now, the magic: we'll put a blurred text-shadow, which will be in front of the background, thus giving the impression of an inner shadow!

    h1 {
      color: transparent;
      background-color: #cc8100;
      background-clip: text;
      text-shadow: 0px 2px 5px #f9c800;
    }
    

    We got it! Yay!

    See the final result.

    Downsides?

    • Only works in Webkit (background-clip can't be text).
    • Multiple shadows? Don't even think.
    • You get an outer glow too.

提交回复
热议问题