Your host:
Stephen Chapman
Stephen Chapman

Nested Styles

Suppose that you have a style that you want to apply to a particular tag but only when that tag is contained within another particular tag? We can handle this with stylesheets by using a nested tag definition. To nest tags we simply specify them one after the other separating them with spaces (and not commas). Here is an example


table table {background-color:red;}

The effect of this example is to turn the background of a table red but only if it is contained within another table.

The two tags that you are nesting don't have to be the same. Here is another example:


table p {color:red;}

This stylesheet code will turn all of the text contained within paragraphs red provided that those paragraphs are contained within a table.

Note that when you specify nested tags like this in your stylesheet definition that the code will not be applied at all unless the second tag is found within the first. You can of course extend this further by nesting more than two tags in your definition if you need to be even more specific.

go to top

Add to del.icio.us

Remortgages - Renegade motorhomes - Loan - Phoenix Pools