I have a website with a global template that contains partial templates, but now I'm stuck in a simple CSS problem:
HTML
<div id="context"> <select id="test"> <option>[Select a value]</option> </select> </div>
Global CSS
The global style sheet defines the default width for all <select> elements inside #context :
div#context select { width: 500px; }
Partial CSS
Now for a partial template (which displays the content inside #context ), I need to override the default width of <select> . I thought it would be so simple:
select#test { width: 150px; }
But I was wrong, it didn’t work. And I think this is because css considers the div#context select be the best match for the element, because it works when I change the partial css template as follows:
div#context select#test { width: 150px; }
Of course, this is not what I want to do, because the partial template does not need to know in which node it is displayed inside the global template.
Any ideas on how I can override the style for a partial template without specifying an element from the global template?
See jsFiddle
source share