Chapter 16
Programmatic CSS
In This Chapter
Scripting
Automating CSS features
Changing style and rules on the fly
Playing with timers
Repeating with a metronome timer
M
ost ordinary CSS is not dynamic, in the sense that it doesn’t respond
to the user. One example that does respond is the pseudo-classes for
the aelement, discussed in the Chapter 15. CSS has a feature called hover,
for example, that turns a hyperlink a different color when the user hovers a
mouse pointer over the link.
In general, however, CSS puts a pretty face on Web pages, simplifies design
across a Web site, and its job is then done. Any interaction with the user
thereafter is left up to programming technologies such as ASP.NET or script-
ing(small sections of programming written into an HTML page using the
<script>element). However, scripts and other programming can be made
to interact with CSS styles, and the result can amplify CSS’s usefulness.
Extending CSS with Scripting .....................................................................
Script code is usually written in VBScript or JavaScript. By default, IE uses
JavaScript, although you can specify VBScript if you prefer. I prefer.
Some experts warn that VBScript is less universal than JavaScript — all
browsers can run JavaScript, but only Internet Explorer recognizes VBScript.
However, given that Internet Explorer is the browser of choice for more than
95 out of 100 Internet users, choosing VBScript seems safe enough. If you’re
concerned, though, go ahead and struggle with JavaScript. It’s more likely to
be buggy and slow to write, but you may prefer it. What do you do about
bugs? More about debugging scripts in Chapter 17.