如何将css / sass样式表关联到rails中的视图? [英] How do you associate a css/sass stylesheet to a view in rails?

查看:187
本文介绍了如何将css / sass样式表关联到rails中的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常普通的问题,我没有找到一个简单的答案。

This is a really generic question, to which I haven't found a simple answer.

我处理的凌乱的旧代码,相同的类/视图。我有 app / styles 中的.sass文件, public / stylesheets public / css

I'm dealing with messy legacy code that specifies style several times for the same classes/views. I have .sass files in app/styles, .css files in public/stylesheets and public/css

我不明白哪些样式表包括哪些,或者如果他们做。
如何在rails中将样式表匹配到特定视图?如何定义样式之间的层次结构,以便可以覆盖其他样式?

I don't understand which stylesheets includes which, or if they ever do. How do you match stylesheets to a specific view in rails? How do you define hierarchy between style so ones can override others?

匹配样式与视图的rails默认值是什么?我在应用程序中看不到任何 stylesheet_link_tag

What's the rails default for matching styles to views? I don't see any stylesheet_link_tag used in the app

推荐答案

最好的方法是在你的应用程序布局中设置一个命名的yield:

The best way would be to put a named yield in your application layout:

<%= yield :head %>

然后在视图中使用阻止的内容:

Then use a content for block in your view:

<% content_for :head do %>
   <%= stylesheet_link_tag :my_css -%>
<% end %>

这篇关于如何将css / sass样式表关联到rails中的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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