内部文本阴影与CSS

问题描述:

我目前正在玩CSS3,并试图实现这样的文字效果(黑色模糊的内阴影):

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

但我找不到一种方法来创建文本阴影 / em>文本。我不知道是否仍然可能,因为box-shadow元素能够像这样渲染阴影:

But I cannot find a way to create text shadows inside the text. I wonder whether it is still possible because the box-shadow element is able to render shadow inside like this:

box-shadow: inset 0px -5px 10px 0px rgba(0, 0, 0, 0.5);

任何想法?

这里有一个小窍门我发现使用:之前:之后伪元素:

Here's a little trick I discovered using the :before and :after pseudo-elements:

.depth {
    color: black;
    position: relative;
}
.depth:before, .depth:after {
    content: attr(title);
    color: rgba(255,255,255,.1);
    position: absolute;
}
.depth:before { top: 1px; left: 1px }
.depth:after  { top: 2px; left: 2px }

title属性需要与内容相同。演示: http://dabblet.com/gist/1609945

The title attribute needs to be the same as the content. Demo: http://dabblet.com/gist/1609945