Evangelism/Firefox3.5/35Days/Articles/text-shadow: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(more examples)
(almost done)
Line 9: Line 9:
== How it works ==
== How it works ==


According to the [http://www.w3.org/TR/css3-text/#text-shadow CSS3 specification], the text-shadow property can have the following values:
According to the [http://www.w3.org/TR/css3-text/#text-shadow CSS3 specification], the <code>text-shadow</code> property can have the following values:


<code>none | [<shadow>, ] * <shadow></code>,
<code>none | [<shadow>, ] * <shadow></code>,
Line 35: Line 35:
<span style="color: #000; background: #fff; font-size: 200%; text-shadow: 2px 2px 0 #888;">I don't like blurs</span>
<span style="color: #000; background: #fff; font-size: 200%; text-shadow: 2px 2px 0 #888;">I don't like blurs</span>


(TODO pic)
[[File:35days-text-shadow-noblur.jpg]]


== Blurry or glowing text, and fancier alternatives ==
== Glowing text, and multiple shadows ==


But due to the flexibility of the feature, the fun does not stop here. By varying the text offset, blur radius, and of course the color, you can achieve various effects, from a mysterious glow:
But due to the flexibility of the feature, the fun does not stop here. By varying the text offset, blur radius, and of course the color, you can achieve various effects, a mysterious glow for example:


TODO ...
  text-shadow: 1px 1px 6px #fff;
 
<span style="color: #fff; background: #000; font-size: 200%; padding: 10px; text-shadow: 1px 1px 5px #fff;">Glowing text</span>
 
[[File:35days-text-shadow-glowing.jpg]]


or a simple, fuzzy blur:
or a simple, fuzzy blur:


TODO ...
  text-shadow: 0px 0px 12px #000;
 
<span style="color: #000; background: #fff; font-size: 200%; padding: 10px; text-shadow: 0px 0px 5px #000;">Blurry text</span>
 
[[File:35days-text-shadow-blurry.jpg]]


Finally, you can add ''more than one shadow'', allowing you to create pretty "hot" effects (courtesy of [http://www.css3.info/preview/text-shadow/ css3.info]):
Finally, you can add ''more than one shadow'', allowing you to create pretty "hot" effects (courtesy of [http://www.css3.info/preview/text-shadow/ css3.info]):
Line 51: Line 59:
   text-shadow: 0 0 4px white, 0 -5px 4px #FFFF33, 2px -10px 6px #FFDD33, -2px -15px 11px #FF8800, 2px -25px 18px #FF2200
   text-shadow: 0 0 4px white, 0 -5px 4px #FFFF33, 2px -10px 6px #FFDD33, -2px -15px 11px #FF8800, 2px -25px 18px #FF2200


<span style="color: #fff; background: #000; font-size: 200%; padding:20px; margin:40px 0; text-shadow:0 0 4px white, 0 -5px 4px #FFFF33, 2px -10px 6px #FFDD33, -2px -15px 11px #FF8800, 2px -25px 18px #FF2200">Multiple shadows are hot</span>
[[File:35days-text-shadow-fire.jpg]]
By the way, the amount of <code>text-shadow</code>s you can apply at the same time in Firefox 3.5 is -- in theory -- unlimited, though you may want to limit it to a reasonable amount.
Like all CSS properties, you can modify <code>text-shadow</code> on the fly using JavaScript:
<!-- NOTE: MediaWiki does not support embedded HTML. In a blog entry, this will look better and actually work -->
<span style="color: #fff; background: #000; font-size: 200%; padding:20px; margin:40px 0;" id="animationtext">Animated shadows with JavaScript</span>
<a href="#" onclick="textshadow.toggleAnimation();return false;">Start/stop animation</a>
<script type="text/javascript">
var textshadow = {
    colors: [
        '#f00', '#0f0', '#00f'
    ],
    shadows: [
        '0 -10px 2px',
        '10px 10px 2px',
        '-10px 10px 2px'
    ],
    state: [0, 1, 2],
   
    animate: function() {
        var t = document.getElementById('animationtext');
        var s = '';
        for (var i = 0; i < 3; i++) {
            if (s) s += ", ";
            var myshadows = this.shadows[this.state[i]];
            s += myshadows + ' ' + this.colors[i];
            this.state[i] = ++this.state[i] % 3; /* rotate */
        }
        t.style.textShadow = s;
    },
   
    toggleAnimation: function() {
        if (this.handle) {
            window.clearInterval(this.handle);
            this.handle = false;
            var t = document.getElementById('animationtext');
            t.style.textShadow = '';
        } else {
            this.handle = window.setInterval(function() { textshadow.animate(); }, 100);
        }
        return false;
    }
}
</script>


<span style="color: #fff; background: #000; font-size: 200%; padding:20px; margin:40px 0; text-shadow:0 0 4px white, 0 -5px 4px #FFFF33, 2px -10px 6px #FFDD33, -2px -15px 11px #FF8800, 2px -25px 18px #FF2200">Multiple shadows are hot</span>


== cross-browser, accessibility etc ==
== Cross-Browser Compatibility ==
TODO compare to images, mention graceful degradation, and cross browser compatibility?
You might ask, how does this behave in other browsers? The good news is, the feature is largely cross-browser compatible, so the times of using pictures for this kind of feature are basically counted.


== (template) ==
* Opera supports <code>text-shadow</code> since version 9.5. According to the [https://developer.mozilla.org/en/CSS/text-shadow Mozilla Developer Center], Opera 9.x supports up to 6 concurrent shadows.
* Safari has had the feature since version 1.1 already (and other WebKit-based browsers along with it).


1. How the feature works.
Internet Explorer does not support the <code>text-shadow</code> property, but the feature degrades gracefully to regular text. In addition, if you want to emulate some of the <code>text-shadow</code> functionality, you can use Microsoft's proprietary [http://msdn.microsoft.com/en-us/library/ms673539%28VS.85%29.aspx ''Shadow'' and ''DropShadow'' filters].


2. How that feature compares to other similar features in other browsers.
A caveat worth mentioning is the ''drawing order'': While Opera 9.x adheres to the CSS'''2''' painting order (i.e., the first specified shadow is drawn at the ''bottom''), Firefox 3.5 adheres to the CSS'''3''' painting order (the first specified shadow is on top).


3. Includes a demonstration and/or graphics that describe how it works.
== Conclusions ==


4. Links to appropriate documentation in developer.mozilla.org.  
TODO ...


== Further resources ==
== Further resources ==
=== Documentation and Tutorials ===
=== Documentation ===
* https://developer.mozilla.org/en/CSS/text-shadow
* https://developer.mozilla.org/en/CSS/text-shadow
* http://www.kremalicious.com/2008/04/make-cool-and-clever-text-effects-with-css-text-shadow/
* http://www.quirksmode.org/css/textshadow.html
* http://www.quirksmode.org/css/textshadow.html
* http://www.w3.org/TR/css3-text/#text-shadow
=== Examples ===
=== Examples ===
* http://maettig.com/code/css/text-shadow.html
* http://maettig.com/code/css/text-shadow.html
* http://www.kremalicious.com/2008/04/make-cool-and-clever-text-effects-with-css-text-shadow/
* https://bug10713.bugzilla.mozilla.org/attachment.cgi?id=273985
* https://bug10713.bugzilla.mozilla.org/attachment.cgi?id=273985
* https://bug10713.bugzilla.mozilla.org/attachment.cgi?id=197360
* https://bug10713.bugzilla.mozilla.org/attachment.cgi?id=197360

Revision as of 21:00, 6 June 2009

Draft-template-image.png THIS PAGE IS A WORKING DRAFT Pencil-emoji U270F-gray.png
The page may be difficult to navigate, and some information on its subject might be incomplete and/or evolving rapidly.
If you have any questions or ideas, please add them as a new topic on the discussion page.

The text-shadow property in CSS3

The text-shadow CSS property does what the name implies: It lets you create a slightly blurred, slightly moved copy of text, which ends up looking somewhat like a real-world shadow.

The text-shadow property was first introduced in CSS2, but as it was improperly defined at the time, its support was dropped again in CSS2.1. The feature was re-introduced with CSS3 and has now made it into the new Firefox 3.5.

How it works

According to the CSS3 specification, the text-shadow property can have the following values:

none | [<shadow>, ] * <shadow>,

while <shadow> is defined as:

[ <color>? <length> <length> <length>? | <length> <length> <length>? <color>? ],

where the first two lengths represent the offset and the third an optional blur radius.

We can make a simple shadow like this, for example:

 text-shadow: 2px 2px 3px #000; 

A simple shadow

35days-text-shadow-simple.jpg

(All of the examples are a live example first, then a picture of the working feature -- so you can compare your browser's behavior with the one of Firefox 3.5 on OS X)

If you are a fan of hard edges, you can just refrain from using a blur radius altogether:

 text-shadow: 2px 2px 3px #888; 

I don't like blurs

35days-text-shadow-noblur.jpg

Glowing text, and multiple shadows

But due to the flexibility of the feature, the fun does not stop here. By varying the text offset, blur radius, and of course the color, you can achieve various effects, a mysterious glow for example:

 text-shadow: 1px 1px 6px #fff;

Glowing text

35days-text-shadow-glowing.jpg

or a simple, fuzzy blur:

 text-shadow: 0px 0px 12px #000;

Blurry text

35days-text-shadow-blurry.jpg

Finally, you can add more than one shadow, allowing you to create pretty "hot" effects (courtesy of css3.info):

 text-shadow: 0 0 4px white, 0 -5px 4px #FFFF33, 2px -10px 6px #FFDD33, -2px -15px 11px #FF8800, 2px -25px 18px #FF2200

Multiple shadows are hot

35days-text-shadow-fire.jpg

By the way, the amount of text-shadows you can apply at the same time in Firefox 3.5 is -- in theory -- unlimited, though you may want to limit it to a reasonable amount.

Like all CSS properties, you can modify text-shadow on the fly using JavaScript:


Animated shadows with JavaScript

<a href="#" onclick="textshadow.toggleAnimation();return false;">Start/stop animation</a>

<script type="text/javascript"> var textshadow = {

   colors: [
       '#f00', '#0f0', '#00f'
   ],
   shadows: [
       '0 -10px 2px',
       '10px 10px 2px',
       '-10px 10px 2px'
   ],
   state: [0, 1, 2],
   
   animate: function() {
       var t = document.getElementById('animationtext');
       var s = ;
       for (var i = 0; i < 3; i++) {
           if (s) s += ", ";
           var myshadows = this.shadows[this.state[i]];
           s += myshadows + ' ' + this.colors[i];
           this.state[i] = ++this.state[i] % 3; /* rotate */
       }
       t.style.textShadow = s;
   },
   
   toggleAnimation: function() {
       if (this.handle) {
           window.clearInterval(this.handle);
           this.handle = false;
           var t = document.getElementById('animationtext');
           t.style.textShadow = ;
       } else {
           this.handle = window.setInterval(function() { textshadow.animate(); }, 100);
       }
       return false;
   }

} </script>


Cross-Browser Compatibility

You might ask, how does this behave in other browsers? The good news is, the feature is largely cross-browser compatible, so the times of using pictures for this kind of feature are basically counted.

  • Opera supports text-shadow since version 9.5. According to the Mozilla Developer Center, Opera 9.x supports up to 6 concurrent shadows.
  • Safari has had the feature since version 1.1 already (and other WebKit-based browsers along with it).

Internet Explorer does not support the text-shadow property, but the feature degrades gracefully to regular text. In addition, if you want to emulate some of the text-shadow functionality, you can use Microsoft's proprietary Shadow and DropShadow filters.

A caveat worth mentioning is the drawing order: While Opera 9.x adheres to the CSS2 painting order (i.e., the first specified shadow is drawn at the bottom), Firefox 3.5 adheres to the CSS3 painting order (the first specified shadow is on top).

Conclusions

TODO ...

Further resources

Documentation

Examples