Reputation: 490
I have DIV ids in an application that are generated dynamically, with an ID at the end. For example: <div id="vote_score_72">
, <div id="vote_score_73">
, <div id="vote_score_74">
and so on.
How can I write that id in the CSS file so I can apply a style to it?
Upvotes: 15
Views: 29932
Reputation: 253308
Further to the suggestion that you should use classes for this functionality (and you should), you can, instead, use the attribute-value-begins-with selector (this may not be the formal name):
div[id^=vote_score] {
color: #f00;
/* and so on... */
}
References:
Upvotes: 33
Reputation: 26591
You should add a common class to all these elements and use this class in your CSS.
Classes are the best way to handle common style for different elements.
Upvotes: 2