Inner text shadow with CSS - css

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?

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

You should be able to do it using the text-shadow, erm somethink like this:
.inner_text_shadow
{
text-shadow: 1px 1px white, -1px -1px #444;
}
here's an example: http://jsfiddle.net/ekDNq/

An elegant example without the need for a positioned wrapper or duplicative content in the markup:
:root {
background: #f2f2f2;
}
h1 {
background-color: #565656;
font: bold 48px 'Futura';
color: transparent;
text-shadow: 0px 2px 3px rgba(255, 255, 255, 0.8);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
}
<center>
<h1>Text With Inner Shadow</h1>
</center>
Looks good on dark backgrounds as well:
:root {
--gunmetal-gray: #2a3439;
background: var(--gunmetal-gray);
}
h1[itemprop="headline"] {
font-family: 'Futura';
font-size: 48px;
padding-bottom: 0.35rem;
font-variant-caps: all-small-caps;
background-color: var(--gunmetal-gray);
color: transparent;
text-shadow: 0px 2px 3px rgba(255, 255, 255, 0.1);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
filter: brightness(3);
}
<center>
<h1 itemprop="headline">Text With Inner Shadow</h1>
</center>
AND ME LINK
AND ME2 LINK

Here's my best try:
.inner_shadow {
color:transparent;
background-color:white;
text-shadow: 0 0 20px rgba(198,28,39,0.8), 0 0 0 black;
font-family:'ProclamateHeavy'; // Or whatever floats your boat
font-size:150px;
}
<span class="inner_shadow">Inner Shadow</span>
The problem is how to clip the shadow that bleeds around the edges!!! I tried in webkit using background-clip:text, but webkit renders the shadow above the background so it doesn't work.
Making a Text Mask with CSS?
Without a top mask layer it is impossible to do a true inner shadow on text.
Perhaps someone should recommend that the W3C add background-clip: reverse-text, that would cut a mask through the background instead of cutting the background to fit inside the text.
Either that or render the text-shadow as part of the background and clip it with background-clip: text.
I tried absolutely positioning an identical text element above it, but the problem is background-clip: text crops the background to fit inside the text, but we need the reverse of that.
I tried using text-stroke: 20px white; on both this element and the one above it, but the text stroke goes in as well as out.
Alternate Methods
Since there is currently no way to make an inverted-text mask in CSS, you could turn to SVG or Canvas and make a text replacement image with the three layers to get your effect.
Since SVG is a subset of XML, SVG text would still be select-able and searchable, and the effect can be produced with less code than Canvas.
It would be harder to achieve this with Canvas because it doesn't have a dom with layers like SVG does.
You could produce the SVG either server-side, or as a javascript text-replacement method in the browser.
Further Reading:
SVG versus Canvas:
http://dev.opera.com/articles/view/svg-or-canvas-choosing-between-the-two/
Clipping and Masking with SVG Text:
http://www.w3.org/TR/SVG/text.html#TextElement

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:
<h1>Get this</h1>
and this CSS:
h1 {
color: black;
background-color: #cc8100;
}
Step 1
Let's start by making the text transparent:
h1 {
color: transparent;
background-color: #cc8100;
}
Step 2
Now, we crop that background to the shape of the text:
h1 {
color: transparent;
background-color: #cc8100;
background-clip: 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;
}
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.

There's no need for multiple shadows or anything fancy like that, you just have to offset your shadow in the negative y-axis.
For dark text on a light background:
text-shadow: 0px -1px 0px rgba(0, 0, 0, .75);
If you have a dark background then you can simply invert the color and y-position:
text-shadow: 0px 1px 0px rgba(255, 255, 255, 0.75);
Play around with the rgba values, the opacity, and the blur to get the effect just right. It will depend a lot on what color font and background you have, and the weightier the font, the better.

You can kind of do this. Unfortunately there's no way to use an inset on text-shadow, but you can fake it with colour and position. Take the blur right down and arrange the shadow along the top right. Something like this might do the trick:
background-color:#D7CFBA;
color:#38373D;
font-weight:bold;
text-shadow:1px 1px 0 #FFFFFF;
... but you'll need to be really, really careful about which colours you use otherwise it will look off. It is essentially an optical illusion so won't work in every context. It also doesn't really look great at smaller font sizes, so be aware of that too.

Try this little gem of a variation:
text-shadow:0 1px 1px rgba(255, 255, 255, 0.5);
I usually take "there's no answer" as a challenge

I've seen many of the proposed solutions, but none were quite what I was hoping.
Here's my best hack at this, where the color is transparent, the background and the top text-shadow are the same color with varying opacities, simulating the mask, and the second text-shadow is a darker, more saturated version of the color you actually want (pretty easy to do with HSLA).
(btw, text and styling based upon a dupe thread's OP)

I've had a few instances where I've needed inner shadows on text, and the following has worked out well for me:
.inner {
color: rgba(252, 195, 67, 0.8);
font-size: 48px;
text-shadow: 1px 2px 3px #fff, 0 0 0 #000;
}
This sets the opacity of the text to 80%, and then creates two shadows:
The first is a white shadow (assuming the text is on a white background) offset 1px from the left and 2px from the top, blurred 3px.
The second is a black shadow which is visible through the 80% opacity text but not through the first shadow, which means it's visible inside the text letters only where the first shadow is displaced (1px from the left and 2px from the top). To change the blur of the this visible shadow, modify the blur parameter for the first layer shadow.
Caveats
This will only work if the desired color of the text can be achieved without it having to be at 100% opacity.
This will only work if the background color is solid (so, it won't work for the questioner's specific example where the text sits on a textured background).

Here is a link talking about how to do this, it should be what you are looking for:
http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/

This looks like it's working: http://tips4php.net/2010/08/nice-css-text-shadow-effects/
He's using multiple shadows to achieve that effect as explained here: http://www.w3.org/Style/Examples/007/text-shadow#multiple

Seems everyone's got an answer to this one. I like the solution from #Web_Designer. But it doesn't need to be as complex as that and you can still get the blurry inner shadow you're looking for.
http://dabblet.com/gist/3877605
.depth {
display: block;
padding: 50px;
color: black;
font: bold 7em Arial, sans-serif;
position: relative;
}
.depth:before {
content: attr(title);
color: transparent;
position: absolute;
text-shadow: 2px 2px 4px rgba(255,255,255,0.3);
}

This is easily the best example I have seen.
http://lab.simurai.com/carveme/
The source is on gitthub
https://github.com/simurai/lab/tree/gh-pages/carveme

Building on the :before :after technique by web_designer, here is something that comes closer to your look:
First, make your text the color of the inner shadow (black-ish in the case of the OP).
Now, use an :after psuedo class to create a transparent duplicate of the original text, placed directly on top of it. Assign a regular text shadow to it with no offset. Assign the original text color to the shadow, and adjust alpha as needed.
http://dabblet.com/gist/2499892
You don't get complete control over spread, etc. of the shadow like you do in PS, but for smaller blur values it is quite passable. The shadow goes past the bounds of the text, so if you are working in an environment with a high contrast background-foreground, it will be obvious. For lower contrast items, especially ones with the same hue, it's not too noticeable. For example, I've been able to make very nice looking etched text in metal backgrounds using this technique.

Here's a great solution for TRUE inset text shadow using the background-clip CSS3 property:
.insetText {
background-color: #666666;
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
color: transparent;
text-shadow: rgba(255,255,255,0.5) 0px 3px 3px;
}

Here's what I came up with after looking at some of the ideas here. The main idea is that the color of the text blends with both shadows, and note that this is being used on a grey background (otherwise the white won't show up well).
.inset {
color: rgba(0,0,0, 0.6);
text-shadow: 1px 1px 1px #fff, 0 0 1px rgba(0,0,0,0.6);
}

There's a much simpler way to achieve this
.inner{color: red; text-shadow: 0 -1px 0 #666;} // #666 is the color of the inner shadow
Voilà

For normal-sized text on small-ish buttons
I found the other ideas on this page to lose their efficacy when used on small buttons with small text lettering. This answer expands on RobertPitt's answer.
Here is the minor tweak:
text-shadow: 1px 1px transparent, -1px -1px black;
$('button').click(function(){
$('button').removeClass('btnActive');
$(this).addClass('btnActive');
});
body{background:#666;}
.btnActive{
border: 1px solid #aaa;
border-top: 1px solid #333;
border-left: 1px solid #333;
color: #ecf0f8;
background-color: #293d70;
background-image: none;
text-shadow: 1px 1px transparent, -1px -1px black;
outline:none;
}
button{
border: 1px solid #446;
border-radius: 3px;
color: white;
background-color: #385499;
background-image: linear-gradient(-180deg,##7d94cf,#1c294a 90%);
cursor: pointer;
font-size: 14px;
font-weight: 600;
padding: 6px 12px;
xxtext-shadow: 1px 1px 2px navy;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btnActive">Option One</button>
<button>Option Two</button>
Note:
I used this site to finesse the color shades.

text-shadow: 4px 4px 2px rgba(150, 150, 150, 1);
for box shadow:
-webkit-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
-moz-box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
box-shadow: 7px 7px 5px rgba(50, 50, 50, 0.75);
you can see online text and box shadow:
online text and box shadow
for more example you can go to this address :
more example code freeclup

Try this example for inset text shadow. Here's the HTML
<h1 class="inset-text-shadow">Inset text shadow trick</h1>
and the CSS
body {
background: #f8f8f8;
}
h1 {
font-family: Helvetica, Arial, sans-serif;
font-weight: bold;
font-size: 6em;
line-height: 1em;
}
.inset-text-shadow {
/* Shadows are visible under slightly transparent text color */
color: rgba(0,0,0,0.6);
text-shadow: 2px 8px 6px rgba(0,0,0,0.2), 0px -5px 35px rgba(255,255,255,0.3);
}
Demo on Jsfiddle

I'm using it from this site, also it looks good. Have a look at it Inner shadow

Related

css inset text background-color in firefox

I want to create an inset text with the CSS. It works nicely on Chrome and safari but doesn't work on firefox and IE also, I have tried countless possibilities but it still doesn't work :-/ Could you please help me with that?
The CSS:
text-align: center;
line-height: 60px;
font-size: 60px;
background-color: #112151;
-moz-background-color: #112151;
-webkit-background-color: #112151;
color: transparent;
text-shadow: 0px 2px 3px rgba(255,255,255,0.5);
-moz-text-shadow: 0px 2px 3px rgba(255,255,255,0.5);
-webkit-background-clip: text;
-moz-background-clip: text;
background-clip: text;
How can I achieve the same design on firefox? It looks like a problem with the background color and the transparent color of the text, but I cant seem to figure out a way how they work together on mozilla and IE.
I did a small example jsfiddle. The trick in creating such a shadow is by adding a text-shadow above and under the text (both are behind, but they're moved up or down).
http://jsfiddle.net/mine/ru6pc/
It seems to work with Firefox, but you'll have problems with IE, I guess. IE < 10 doesn't support CSS-text-shadow yet, so you might take a look at pie-CSS (I don't know, if they're supporting it, but might be worth a look).
.inset {
font-family: Arial;
font-weight: bold;
font-size: 20pt;
color: #4e830f;
text-shadow: 0px -1px 2px rgba(0, 0, 0, 0.75),
0px 1px 2px rgba(255, 255, 255, 0.75);
}

Weird border with CSS box-shadow

I applied the following style to the submit button visible in this test page :
border-radius: 25px;
border: none;
background: #FE6181;
box-shadow: 0 0 0px 0.4em #f4f4f4 inset;
padding: 20px;
As you can see there's some awfully irregular pink border which has nothing to do here around the button. Why is that ?
Your inset box shadow doesn't QUITE fill right out to the edges, leaving the background visible.
I'm not familiar with box shadow, but you need a shadow that is both inset and outset, but only outset by about a pixel, so it covers up the outline.
The property "box-shadow" apparently render bad because of the background.
In your case using "border" may solve the problem
border-radius: 25px;
border: 0.4em solid #F4F4F4;
background: #FE6181;
padding: 20px;

Creating a Fuzzy Border in CSS 3

Here's my source image:
And my source image zoomed in:
Any thoughts on how to accomplish this with only CSS3? Notice the slight bleed upwards into the element.
Update: I've removed the vendor prefixes, since almost every browser that supports these properties do not need them. Dropping them is considered a best practice at this point.
See Caniuse page for border-radius and box-shadow.
the best (and only) way to do this is to use multiple box-shadows:
element {
box-shadow: rgba(0,0,0,0.2) 0px 2px 3px, inset rgba(0,0,0,0.2) 0px -1px 2px;
border-radius: 20px;
}
box-shadow works like this:
box-shadow: [direction (inset)] [color] [Horizontal Distance] [Vertical Distance] [size];
border-radius works like this:
border-radius: [size];
/*or*/
border-radius: [topleft/bottomright size] [topright/bottomleft size];
/*or*/
border-radius: [topleft] [topright] [bottomright] [bottomleft];
you can specify the Height an length of the curve like this:
border-radius: [tl-width] [tr-width] [br-width] [bl-width] / [tl-height] [tr-height] [br-height] [bl-height];
It's just using two box shadows, one inset and the other outset, i.e:
.box {
width: 100px;
height: 100px;
box-shadow: 0 3px 6px rgba(0,0,0,0.3), inset 0 -3px 3px rgba(0,0,0,0.1);
border: solid #ccc 1px;
border-radius: 10px;
margin: 50px 0 0 50px;
}
See it here: http://jsfiddle.net/WYLJv/
This is actually done with two CSS3 box-shadows.
CSS:
#fuzz
{
height: 100px;
width: 100px;
border-radius: 5px;
border: 1px solid #333;
box-shadow: 0px 0px 5px #333, inset 0px 0px 2px #333;
}
You can see it in action when i get back to real computer to edit the fiddle :-) (using my tablet now)
Obviously change the colors to your taste :)
Look at css3 property border-radius. It has options for x and y offset color and the blur radius. In your case a greyish color no offset and blur if 4px ought to work.
I'm a bit late but, yes, use border radius and box-shadow(s) and you should be good to go.
.block {
border-radius:6px;
box-shadow: inset 0px 0px 2px 2px #aaa, 3px 3px 5px 0px #eee;
}
Try adding a border-radius and a text-shadow in your css.
.box {
border-radius:20px;
text-shadow:2px 2px black;
}
Hope this helps.
You can probably just get away with setting the border to a light colour and outline to a darker colour, then just set the border-radius. Note I haven't tested this, and if memory serves the outline does not curve with border-radius. Also note that border-radius requires several attributes to be set to become cross-browser compatible. Refer to http://perishablepress.com/press/2008/11/24/perfect-rounded-corners-with-css/ for more info.
If this fails, you could always use an inner-div, which you set to position absolute, left 0, right 0, top 0 and bottom 0 and then use that as either the inner or outer border. Setting the border-radius will definitely work then.
Regards,
Richard

CSS3 Gradients to reproduce an 'inner glow' effect from Illustrator with border-radius applied

I am in the process of trying to get my head properly around CSS3 Gradients (specifically radial ones) and in doing so I think I've set myself a relatively tough challenge.
In Adobe Illustrator I have created the following 'button' style.
To create this image I created a rectangle with a background colour of rgb(63,64,63) or #3F403F, then 'stylized' it to have a 15px border radius.
I then applied an 'inner glow' to it with a 25% opacity, 8px blur, white from the center. Finally, I applied a 3pt white stroke on it. (I'm telling you all of this in case you wished to reproduce it, if the image above isn't sufficient.)
So, my question is thus:
Is it possible to recreate this 'button' using CSS without the need for an image?
I am aware of the 'limitations' of Internet Explorer (and for the sake of this experiment, I couldn't give a monkeys). I am also aware of the small 'bug' in webkit which incorrectly renders an element with a background colour, border-radius and a border (with a different color to the background-color) - it lets the background color bleed through on the curved corners.
My best attempt so far is fairly pathetic, but for reference here is the code:
section#featured footer p a
{
color: rgb(255,255,255);
text-shadow: 1px 1px 1px rgba(0,0,0,0.6);
text-decoration: none;
padding: 5px 10px;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border: 3px solid rgb(255,255,255);
background: rgb(98,99,100);
background: -moz-radial-gradient(
50% 50%,
farthest-side,
#626364,
#545454
);
background: -webkit-gradient(
radial,
50% 50%,
1px,
50% 50%,
5px,
from(rgb(98,99,100)),
to(rgb(84,84,84))
);
}
Basically, terrible. Any hints or tips gratefully accepted and thank you very much in advance for them!
It seems like you're trying to produce a gradient to replicate this:
"I then applied an 'inner glow' to it with a 25% opacity, 8px blur, white from the center."
You can do exactly that using an inset box-shadow. For example:
-moz-box-shadow: inset 0 0 8px rgba(0,0,0, 0.25);
-webkit-box-shadow: inset 0 0 8px rgba(0,0,0, 0.25);
With no extra markup:
Radial gradients are very difficult to control, and work much more differently across browsers than linear gradients do. And, unlike an inner glow, they will actually be circular rather than matching the mostly-rectangular contours of your box.
Since every browser that allows box-shadows also allows rgba and multiple-backgrounds, I would use a combination of two linear gradients, stacked and using rgba colors - one horizontally and one vertically. Something along these lines (replacing my colors with what you need):
section#featured footer p a {
background-color: #000;
background-image: -moz-linear-gradient(
left,
rgba(255,255,255,.5),
rgba(255,255,255,0) 10%,
rgba(255,255,255,0) 90%,
rgba(255,255,255,.5)
), -moz-linear-gradient(
top,
rgba(255,255,255,.5),
rgba(255,255,255,0) 10%,
rgba(255,255,255,0) 90%,
rgba(255,255,255,.5)
);
background-image: -webkit-gradient(
/* webkit's syntax for the same horizontal gradient */
), -webkit-gradient(
/* webkit's syntax for the same vertical gradient */
);
}
You can also create a radial gradient that goes from white to transparent on an overlayed div. I used this awesome css3 generating tool that gives you the all the needed css3 for cross browser compatibility.
http://www.colorzilla.com/gradient-editor/
Hope this helps somebody!
Well I got to say... your question interested me a lot so I went at it.
I found a solution, but it does use a nested <span> tag which is a little uncouth, but it is practically identical to your image.
Here's what the HTML looks like:
<span>Carry on reading →</span>
Notice the nested <span> inside of the <a>. The non-breaking spaces are just there to give the arrow the same amount of room you have in your picture.
And here's the CSS:
a.dark-button {
font: 11pt/11pt "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 100;
color: white;
text-decoration: none;
background-color: #555;
border: 3px solid white;
-moz-border-radius: 15px; padding: 5px 3px;
text-shadow: 1px 1px 2px #111;
}
a.dark-button span {
background-color: #666;
padding: 2px 12px;
-moz-border-radius: 15px;
-moz-box-shadow: 0 0 1px #666, 0 0 2px #666, 0 0 3px #666, 0 0 4px #666, 0 0 5px #666, 0 0 7px #666;
}
Basically to get the inner-glow effect, I did an outer glow (in the form of a drop shadow) from an inner element. Hope that makes sense.
To see it live: http://ianstormtaylor.com/experiments/css-buttons
Have fun!

webkit css transitions

Trying out some webkit transitions on a site and have come across a problem. The hover state on my links adds a 1px border and decreases the padding so that the positioning stays the same. Works fine normally, but not when I add the transition. Obviously, as I'm only making 1px changes, it happens abruptly, but it doesn't happen at the same time - the padding changes before the border, so the whole thing 'jiggles'.
#loginbuttons a {
text-decoration: none;
padding: 5px;
-webkit-transition: all 0.5s ease;
}
#loginbuttons a:hover {
padding: 4px;
border: 1px solid black;
background-color: yellow;
}
The best way I've found to get around this is to have a white border on the normal state so that it's only changing the color, but I want it to be transparent. Also, is there any way of fading the background color in from white instead of black without setting a white background color? Again, I want it to be transparent, but it just looks weird going gray and then yellow!
I've got transitions on my navigation menu as well, and the same thing happens (this time altering the padding and margin):
#nav ul li a {
color: white;
padding: 10px 10px 8px 10px;
margin: 0 5px;
border: 1px solid black;
opacity: 0.85;
-webkit-transition: all, 0.5s;
}
#nav ul li a:hover, #nav ul li a.selected {
color: black;
padding: 13px 13px 11px 13px;
margin: 0 2px;
text-shadow: 2px 2px 4px white, -2px -2px 4px white, 2px -2px 4px white, -2px 2px 4px white;
opacity: 1;
-webkit-box-shadow: 0px 0px 8px #888;
}
Hmmm, just tried bumping the values up a bit, and even changing the margin and padding by 15px using a linear transition still produces a small (looks like 1 or 2px) glitch. Same thing happens in safari and chrome.
Anyone got any ideas how to make it smooth? Or sort out the color issue? Think it would be better doing it with jquery (ignoring the cross-browser support!)? Might go and see if the same thing happens with opera...
edit: seems like the 10.5a opera release for macs still doesn't support transitions...
First of all, it might be worthy to try border: 1px solid transparent so that the transition changes only the color of the border. In that sense the padding stays the same and there is less browser guesswork. If transparent does not work, any color with an alpha value of 0, for example, rgba(0, 0, 0, 0) is also acceptable.
Opera Presto 2.3 supports transitions, but it asks for different statements — -o-transition-property et al. Hope that this link would be of good use. Firefox does CSS transitions too, and they have a demo page. To make transitions work in Firefox, one must use -moz- statements.

Resources