Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inner text shadow with CSS

Tags:

text

css

shadow

I am currently playing around with CSS3 and trying to achieve a text effect like this (the black blurry inner 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); 

Any ideas?

like image 563
ericteubert Avatar asked May 22 '10 19:05

ericteubert


People also ask

How do I add a shadow effect to text in CSS?

CSS Syntaxtext-shadow: h-shadow v-shadow blur-radius color|none|initial|inherit; Note: To add more than one shadow to the text, add a comma-separated list of shadows.


1 Answers

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 } 

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

like image 100
Web_Designer Avatar answered Sep 28 '22 04:09

Web_Designer