How to add a style sheet property to a sub element

Sometimes, for reasons that elude me, you can not use a class or an id for an element placed within another element that already uses a class or an id. To get around this you must define the element you want to style in your style sheet as a sub element of the principal class or id.

For example, if you want to have an image within a div and you want both the div and the image to use style sheet defined properties, then your style sheet should look like this:

.div {
define properties for the div
}

.div img {
define properties for the image within the div
}

You could also use id instead of class and it would then look like:

#div {
define properties for the div
}

#div img {
define properties for the image within the div
}

Comments are closed.