I use the following code on my page:
<div id="itemstable" class="item_type1">
...other divs here...
</div>
And in my CSS file I have this code:
.item_type1 div {
background-image: url(images/type1.giff);
}
the problem is there are a lot of different item types so I will need to have a lot of lines in my CSS file. I was wondering how to apply the background-image: url(images/type1.giff); style to the nested divs without assigning it to each one. eg. I want to change the code for the “itemstable” div so that it applies a css rule to the nested divs.
Is this possible?
EDIT: I’m looking for something like this:
<div id="itemstable" style="SET BACKGROUND IMG FOR NESTED DIVS HERE">
...other divs here...
</div>
(If I’m understanding the question correctly:)
Think about using a different ID/class scheme. I don’t know about the further specifics of your structure, but
id="itemstable" class="item_type1"seems slightly redundant to me. Canitemstablebe anything else thanitem_type1? Try to apply more generic class names and keep the specific cases for IDs.Failing that, you can add another class that is responsible for adding the background image:
class="item_type1 item_types".EDIT
Since it seems sheer mass is the main problem (not applying the style as the title suggests) it’s probably best to dynamically insert a style in the page header. Something along the lines of:
Inline styles can only apply to the element directly, not one of its children. I.e.:
The background only applies to this one div.
You can’t use selectors in inline styles like: