Click to skip over navigation
 

lecture 4: style classes

<< previous slide

return to lesson 4 index

next slide >>




Most of the things referred to in the previous slide can be defined using styles (the exception being rowspan and colspan). As ever, you can do this in an external style sheet, in the document header (using the <style> tag) or in ad hoc style definitions (using the style attribute in tags).

It can get tedious to keep defining ad hoc styles, but if you want to avoid using too many of them then a problem emerges. With tables it can be quite common to want two separate definitions for the same tag, particularly the <td> tag. These definitions will be re-used regularly, for the sake of consistency. So ideally what you need is a way to make definitions non-universal, while at the same time avoiding the tedium of typing long ad hoc style attributes on every page or even several times on each page.

The answer is the style sheet class. The sample page here - which serves as an illustration of several of the techniques shown in this lecture - uses classes to distinguish the three kinds of table cell from each other. The code for this page is given on your handout and I suggest you look at it alongside the page itself, which you can open by clicking on the screen shot.

In style definitions, create classes by using a full stop then the class name (which you can choose) after the tag name. This class is then "called" by using the class attribute in the actual tag. Note that classes inherit all properties from the "parent" tag, so in a class (as with a pseudo-class like a:hover you only need define what is actually different from the parent (and/or the browser default).

Also note that you can create "generic" classes where properties are not assigned to particular tags in advance but can be called by any tag. This is done by omitting the tag name from the style definition but retaining the full stop and the class name. These generic classes are still called by the class attribute as before.

Ensure you read the page in the online teaching materials on style classes and practice the technique on your own site. Remember also that you can use this technique with any tag, not just table tags.




<< previous slide

return to lesson 4 index

next slide >>