I would like to add a black outline around each character, so if the font id on the same color background as the foreground it is still readable.
Can this be done in CSS with or without browser specific css?
Sometimes you need an outline around your text. A recent project required me to place white text on a multicolored image background, so giving that text a black outline was important for readability. Should be easy, right? Just declare text-outline: 1px black solid; , and we're done.
In CSS, we may apply borders to a font by using the text-stroke property on a text. To access the feature, we must use the webkit prefix before the text-stroke attribute. However, it is only compatible with web-kit-based browsers such as Safari and Chrome.
You can simulate it with the CSS 2.1 text-shadow
property:
p { color: #fff; text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000; }
This is, of course, not supported in IE9 and below. See: http://www.jsfiddle.net/yijiang/UCjgg/ for a simple demo.
There is an explicit -webkit way to add text outline, which is with -text-stroke. This is the experimental implementation of the equivalent standards track proposal (called text-outline in the CSS3 spec docs).
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