IE不应用动态加载的CSS [英] IE doesn't apply dynamically loaded CSS

查看:115
本文介绍了IE不应用动态加载的CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它似乎IE(至少旧版本)不适用动态加载的CSS。如果通过ajax将包含CSS的页面加载到lightbox或colorbox中,这可能是一个痛点。

It appears as though IE (older versions at least) does not apply CSS that is loaded dynamically. This can be a pain point if you load a page containing CSS via ajax into a "lightbox" or "colorbox".

例如,假设您的HTML页面有一个div命名为taco:

For example, say your HTML page has a div named "taco":

<style>#taco {color:green;}</style>
<div id="taco">Hola Mundo!</div>

Hola Mundo!将是绿色的,因为CSS包含在原始的HTML页面中。然后,一些Javascript发生并附加到taco:

"Hola Mundo!" will be green since the CSS was included in the original HTML page. Then some Javascript happens and appends this to "taco":

<style>#taco {color:green;}</style>
<div id="taco">
  Hola Mundo!
  <style>#burrito {color:red;}</style>
  <span id="burrito">mmmm burrito</span>
</div>

在除IE之外的所有浏览器中,burrito的字体将为红色。

In all browsers except IE, burrito's font will be red.

那么有没有办法在IE中这样做?

So is there a way to do this in IE? It seems as though there is not.

推荐答案

style 标记是只允许在部分。将它放在别的地方根本无效,与IE无关。

The style tag is only allowed in the head section. Placing it somewhere else is simply invalid and that has nothing to do with IE.

更多资讯

顺便说一句,为了解决你的问题,如果你不能把样式放在一个全局样式表,你可以使用'style'属性修改元素:

By the way, to solve your problem if you can´t put the styles in a global style-sheet, you can use the 'style' attribute to modify elements:

<p style="...">

或者您可以使用 iframe 您必须提供整个网页,而不只是几个标签。

Or you can use an iframe but then you'd have to serve a whole page instead of just a few tags.

这篇关于IE不应用动态加载的CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆