I'm trying to add an outline to text using the CSS text-shadow
property here.
The problem is that the shadow corners don't always meet. If you look below, you can see the problem on the upper right corner of the Y.
It doesn't look too bad with this font but with some fonts that my code uses it makes a big difference.
Is there a way to have the text completely surrounded by the box-shadow, especialy in the cornerns?
.shadowOutline {
font: normal 200pt Arial;color: #fff;
text-shadow:
-1px 1px #ff0000,
-1px -1px #ff0000,
1px 1px #ff0000,
1px -1px #ff0000,
-2px 2px #ff0000,
-2px -2px #ff0000,
2px 2px #ff0000,
2px -2px #ff0000;
-webkit-font-smoothing: antialiased;
}
<div class="shadowOutline">My</div>
Please use the below css code. text-shadow: 0 0 6px #000000; It helps to provide center text shadow.
Text shadow # The text-shadow property is very similar to the box-shadow property. It only works on text nodes. The values for text-shadow are the same as box-shadow and in the same order. The only difference is that text-shadow has no spread value and no inset keyword.
You can comma separate box-shadow any many times as you like.
A shadow is a dark area on a bright surface. It is caused by something blocking a source of light. A shadow's outline, called a silhouette, will have the same shape as the object blocking the light.
You can do it with svg ,and you have a perfect resault
text{font-size:100px;
fill: none;
stroke: red;
stroke-width:2px;
stroke-linejoin: round;
}
<svg height="120" width="480">
<text x="0" y="90" >I love SVG!</text>
</svg>
or you can use it directly with inline css like this :
<svg height="100" width="480">
<text x="0" y="80" fill="white" stroke="red" style="font-size:100px;stroke-width:2px;">I love SVG!</text>
</svg>
I managed to get it a little better using :
.shadowOutline {
font: normal 200pt Arial;color: #fff;
text-shadow:
-2px -2px 0 #ff0000,
2px -2px 0 #ff0000,
-2px 2px 0 #ff0000,
2px 2px 0 #ff0000,
2px 0px 0 #ff0000,
-2px 0px 0 #ff0000,
0px 2px 0 #ff0000,
0px -2px 0 #ff0000;
-webkit-font-smoothing: antialiased;
}
<div class="shadowOutline">My</div>
The point is to offset the text-shadow in all directions :
But also
Keep in mind, that for values greater than one pixel you'll have to fill the gaps of sharp corner shadows. See for example letter "X" with (attempt of) ten pixels thick outline, first made by eight, second by twenty four shadows:
See this example
span {
font: normal 200pt Arial;
color: #fff;
letter-spacing: 20px
}
.eight-shadows {
text-shadow:
-10px -10px 0 #f00,
00px -10px 0 #f00,
10px -10px 0 #f00,
10px 00px 0 #f00,
10px 10px 0 #f00,
00px 10px 0 #f00,
-10px 10px 0 #f00,
-10px 00px 0 #f00;
}
.twenty-four-shadows {
text-shadow:
-10px -10px 0 #f00,
00px -10px 0 #f00,
10px -10px 0 #f00,
10px 00px 0 #f00,
10px 10px 0 #f00,
00px 10px 0 #f00,
-10px 10px 0 #f00,
-10px 00px 0 #f00,
-05px -10px 0 #f00,
00px -10px 0 #f00,
05px -10px 0 #f00,
05px 00px 0 #f00,
05px 10px 0 #f00,
00px 10px 0 #f00,
-05px 10px 0 #f00,
-05px 00px 0 #f00,
-10px -05px 0 #f00,
00px -05px 0 #f00,
10px -05px 0 #f00,
10px 00px 0 #f00,
10px 05px 0 #f00,
00px 05px 0 #f00,
-10px 05px 0 #f00,
-10px 00px 0 #f00
}
<span class="eight-shadows">X</span>
<span class="twenty-four-shadows">X</span>
(In fact the middle "horizontal" shadows chunk could be omitted for this sample, because it contains no sharp vertical corner, but I left it there for clarity.)
To get "solid" 10px corner outlines you'd have to use 288 (= 4×9×8) shadows, and even then the result will be vertical or horizontal lines near the sharp corners instead of sharp ones.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With