我的代码中有以下行,试图将样式加载到iFrame中:
<iframe style='color:blue;margin-left:30px;@import('../../custom/courses/css/stylesheets/course.css'); />
有两个问题:
- 是否可以像我在上面尝试的那样使用@import导入代码
- 我的浏览器中的 html 代码输出以下内容:
<iframe style="color:blue;margin-left:30px;@import(" ..="" custom="" courses="" css="" stylesheets="" course.css');</iframe>
所以,我的css url路径非常混乱。
更新
我的代码:
(function($){
var cssLink = document.createElement("link")
cssLink.href = "../../custom/courses/css/stylesheets/course.css";
cssLink.rel = "stylesheet";
cssLink.type = "text/css";
// frames['iframe'].document.body.appendChild(cssLink);
jQuery('iframe.field-iframe-instance').css('border', '1px solid red');//.find('body').appendChild(cssLink);
})(jQuery);
iframe 上的代码无法生效
你不能那样做。您可以将样式包含在 iframe 目标源中,也可以通过 javascript 附加它。看看这个: 如何将CSS应用于iframe?