Apply external stylesheet to a particular section
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开发者_如何学JAVA 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.
精彩评论