Rails 4 x SASS:在Internet Explorer中加载特定的样式表 [英] Rails 4 x SASS: load specific stylesheet in Internet Explorer

查看:195
本文介绍了Rails 4 x SASS:在Internet Explorer中加载特定的样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails 4应用程序中,我正在尝试实现一个条件来为Internet Explorer VS加载不同的样式表。其他浏览器。

In my Rails 4 app, I am trying to implement a conditional to load different stylesheets for Internet Explorer VS. other browsers.

我有一个 app / views / layout / _header.html.erb partial with:

I have an app/views/layout/_header.html.erb partial with:

<head>
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
  <!--[if !IE]><!-->
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= stylesheet_link_tag 'ie', media: 'all', 'data-turbolinks-track' => true %>
  <!--<![endif]-->
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>

我在 app / assets / stylesheets

custom / # with all my model-specific stylesheets here, such as posts.scss
application.scss
custom.scss
ie.scss

In application.scss 我有:

@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap/theme";
@import "bootstrap-datetimepicker";
@import "font-awesome-sprockets";
@import "font-awesome";
@import "simple_calendar";
@import "custom.scss";
@import "custom/**/*";

注意:ie.scss中的IE特定规则非常轻,不到20行代码。

Note: the IE-specific rules in ie.scss are very light, less than 20 lines of code.

然而,当我在Internet Explorer中启动应用程序时,CSS规则来自 ie.scss 不予考虑。

However, when I launch the app in Internet Explorer, the CSS rules from ie.scss are not taken into account.

如何制作 ie.scss 当用户在Internet Explorer中启动应用程序时加载文件?

How can I make the ie.scss file load when the user launches the app in Internet Explorer?

推荐答案

对于所有IE版本:

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<!-- Calling application stylesheet file only once -->
<!--[if IE]> 
  <%= stylesheet_link_tag 'ie', media: 'all', 'data-turbolinks-track' => true %> 
<![endif]-->

而不是指定ie.css,您可以将其更改为:

And instead of specifying ie.css, you can change it to:

Rails.application.config.assets.precompile += %w( *.css )

这样您就不必分别添加每个文件了。
我在项目中通常使用的内容:

So that you don't have to add each and every file separately. What I generally use in my projects:

Rails.application.config.assets.precompile += %w( *.js *.css *.png *.jpg *.jpeg )

这篇关于Rails 4 x SASS:在Internet Explorer中加载特定的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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