• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1844
  • Last Modified:

CSS Overriding and Scope

<div id="foo">
..... more markup .....

Assume all CSS rules for the content inside have an id selector of "foo" as the prefix


#foo p{...}
#foo #myspan{....}

Is there any way for these rules to modify/affect CSS outside of the div? Reason being I plan on pre-fixing in this fashion to all user supplied CSS rules so my main page cannot be modified (I don't want to apply !important on all of my rules). Thanks
1 Solution
#foo p {}

Means only apply the style to paragraphs inside an element with the ID foo.

#foo #myspan{}

Means only apply the style to a element with the ID myspan inside an element with the ID foor.

If p or #myspan are anywhere else on the page the styles will not be applied to them, they must be inside foo for the style to be applied.

No any style prefixed with #foo can only affect the styling inside the element with the ID foo.

This will do what you are after.

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now