[英]Can I use Twitter Bootstrap on only a portion of my Rails app?
I'm trying to gradually move a large existing rails 4 app to Bootstrap. 我正在尝试逐步将现有的大型Rails 4应用程序移至Bootstrap。 Is there any way to just use bootstrap with only a certain layout and not others?
有什么方法可以仅使用特定布局而不使用其他布局的引导程序? Or could I just use bootstrap within a certain body tag?
还是可以在某个身体标签内使用引导程序? I'm trying to avoid pulling in bootstrap font styling, etc. on all existing views.
我试图避免在所有现有视图上引入自举字体样式等。
I am using the asset pipeline. 我正在使用资产管道。 Here's how I'm using the Bootstrap css in my application.css.scss file:
这是我在application.css.scss文件中使用Bootstrap CSS的方式:
@import "bootstrap-sprockets";
@import "bootstrap";
@import '*';
Say you have two layout files, application.html.erb and admin.html.erb . 假设您有两个布局文件application.html.erb和admin.html.erb 。 You would then simply create two different manifest files, application.css.scss and admin.css.scss .
然后,您只需创建两个不同的清单文件application.css.scss和admin.css.scss即可 。 However, you should also create a separate CSS file for Bootstrap, bootstrap_custom.css.scss .
但是,您还应该为Bootstrap创建一个单独的CSS文件bootstrap_custom.css.scss 。
bootstrap_custom.css.scss bootstrap_custom.css.scss
@import "bootstrap-sprockets";
@import "bootstrap";
Note: You don't want to use @import
in your manifest files since it will need to recompile each time and thus slow down development. 注意:您不想在清单文件中使用
@import
,因为它将需要每次重新编译,从而减慢了开发速度。 Instead, use require
when possible! 相反,请尽可能使用
require
!
application.css.scss application.css.scss
//= require bootstrap_custom
//= require_tree .
admin.css.scss admin.css.scss
//= require_tree .
Then, correspondingly in your layout files 然后,在您的布局文件中
application.html.erb application.html.erb
<%= stylesheet_link_tag "application" %>
admin.html.erb admin.html.erb
<%= stylesheet_link_tag "admin" %>
So now, your application layout has bootstrap and admin layout doesn't. 因此,现在,您的应用程序布局具有引导程序,而管理员布局则没有。
Bootstrap仅会在其被调用的网页上的选择器中关联的类上调用。您可以调用以仅在您要应用其的页面上加载Bootstrap。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.