I have a web service where people can edit their pages CSS, but I have a bar on the footer of that page that I want to make consistend on every page…
People are, right now, able to “remove” it with CSS and I really didn’t want to go and parse the CSS to remove rules related to that bar… Is there a way to preserve the styles or re-aply them after load to keep the bar always visible?
If you modify the user-created CSS as you save it; adding descendant selectors to all their rules, you can limit the effect of their styles to an element of your choosing. If you take this HTML:
The user creates the following stylesheet, trying to hide your footer:
When the user saves their styles, you parse through and add
#userEditableAreato all of their rules, so they only work on elements inside<div id="userEditableArea">. This should be pretty easy to accomplish with a regex pass or two.Anything you don’t want them to mess with, put outside of #userEditableArea.
This should be pretty robust – more so than using !important rules or high-specificity selectors, and doesn’t require any JS.