On my website I allow user-generated style sheets to be used. But I don’t want those styles to affect the the whole website, just a separate section/div. Is there way to do that, without going through the whole custom style sheet and adding my div selector to every css rule?
For example if a user has:
a, span{color:white;}
div{padding:10px;}
Right now I have to parse it out and replace to
#mySection a, #mySection span{color:white;}
#mySection div{padding:10px;}
Nope, unfortunately there isn’t. There is no CSS equivalent to the
<base>tag or similar that would limit the scope of a CSS rule.You will have to prepend every rule with the element(s) you want to apply them to, or load the user styled content in an iframe.