Reputation: 8587
We're currently having to write some widgets that are going to be embedded on various pages. As far as I know, I have two possible options to protect these widgets from loose CSS rules (e.g. a general p { background-color: red }
for example). These are:
Using a reset stylesheet to ensure all CSS properties for the widget elements are set to known defaults. Using a CSS preprocessor like Less, this can be simple enough:
html body #myWidgetID {
.resetCSSMixin();
}
Embedding the element into an iframe
much like suggested on HTML5 Rocks.
Option 1 is a known entity to me. It's not pretty but it'll work. Option 2 I'm not too sure about. Would a large amount of iframes slow the page down? We now a lot of our sites will be visited on old hardware & slow internet speeds. We also need to support old IE 8 - Could there be browser compatibility issues? We certainly can't use the newer iframe attributes.
Can anyone suggest any reasons why I shouldn't go with option 2? It sounds like the nicer option, but I'd like a little more guidance before making the call.
Upvotes: 1
Views: 223
Reputation: 116110
iframes
are a very old feature, so IE8 support is not an issue. The main difference is that an iframe loads a separate document into a frame. This will have a couple of effects:
Upvotes: 1
Reputation: 752
If you care about a CSS property, you will style your widget element with that property either using a more specific rule in the stylesheet or in the style DOM attribute. Either way, it will override loose selectors.
If you don't care about a CSS property, there is no point in resetting it, and you should probably allow it to be themed.
Upvotes: 0