I overwrite some of the jQuery UI CSS classes in my MVC Views.
I want to move all the style elements to an external style file. But I don’t want the overwritten CSS classes to apply to all the views.
Is there a way to specify CSS classes for a particular view, or any recommended way to approach this?
I’d rather keep just one css file if possible.
Assuming that when you say “classes” you mean “rule-sets”:
Since you have added a requirement to stick to one CSS file (and I assume you don’t want an inline
<style>element):Prefix each selector with an id selector and a descendent combinator:
#someidThen add the id to the body element of the view:
<body id="someid">Thus:
becomes
Warning: This will increase the specificity of each selector (in the group of rule-sets specific to your view). This could change the order in which these rules and the generic “apply to every page” rules are applied. You could avoid this by prefixing all the shared rules with
#genericand adding<html id="generic" lang="en">.