[英]Dynamic Load CSS in Rails for IE
I have an app in rails
. 我在
rails
有一个应用程序。 In my application, there are places where partial use. 在我的应用程序中,有一些地方可以部分使用。
Each partial to use, brings its own CSS
每个要使用的部分,都有自己的
CSS
The problem shows up with our dear Internet Explorer 7
and Internet Explorer 8
which do not let me insert CSS
outside header. 我们亲爱的
Internet Explorer 7
和Internet Explorer 8
,它们不允许我将CSS
插入标头之外。 I tried to do it the following way: 我尝试通过以下方式进行操作:
css=stylesheet_link_tag 'my_partial'
$(CSS).appendTo("head");
It is working perfectly in Chrome, Safari, and Firefox. 它可以在Chrome,Safari和Firefox中完美运行。 However, I can not load the
CSS
in Internet Explorer. 但是,我无法在Internet Explorer中加载
CSS
。 Can someone give me an idea of how to solve this problem? 有人可以给我一个如何解决这个问题的想法吗?
It's possible to include a yield
section in the head section of your layout. 可以在布局的头部包含一个
yield
区域。 You can then do content_for
in each partial that includes your customised CSS. 然后,您可以在包含自定义CSS的每个部分中执行
content_for
。
eg in layouts/application.html.erb
例如在
layouts/application.html.erb
<html>
<head>
<!-- blah blah title and regular css here -->
<%= yield :extra_stylesheets %>
</head>
...
Then in partials: 然后分部分:
<% content_for :extra_stylesheets do %>
<%= stylesheet_link_tag 'my_partial_stylesheet' %>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.