Using JavaScript with CSS

There are two primary ways in which you might utilize JavaScript in conjunction with CSS: swapping browser-specific style sheets and creating dynamic styles triggered by the user or other actions.

A couple of problems, however, sometimes occur when using a browser sniffer to redirect users to the correct style sheet based on their browser:

  • There are no consistent browser-identification standards, meaning that some browsers are liable to be misidentified, no matter how carefully you think you've crafted your script.

  • Browser sniffer scripts have to be updated and maintained to account for new browsers. This can be a headache.

One approach that you might find useful, however, was covered in Chapter 16, “Providing for Backward ...

Get Cascading Style Sheets (CSS) by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.