简体   繁体   English

我可以仅在我的Rails应用程序的一部分上使用Twitter Bootstrap吗?

[英]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.erbadmin.html.erb You would then simply create two different manifest files, application.css.scss and admin.css.scss . 然后,您只需创建两个不同的清单文件application.css.scssadmin.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.

相关问题 如何使用twitter-bootstrap-rails gem禁用部分Twitter Bootstrap响应式设计? - How do I disable a portion of Twitter Bootstrap responsive design using twitter-bootstrap-rails gem? Twitter Bootstrap导航栏在我的Rails应用程序上崩溃 - twitter bootstrap navbar collapse on my rails app 更新现有的rails应用程序以使用Twitter Bootstrap? - Updating existing rails app to use Twitter Bootstrap? 如何在rails app中使用twitter bootstrap和bootstrap-sass? - How to use twitter bootstrap with bootstrap-sass in rails app? 如何在Rails应用程序中使用Bootstrap中的进度栏​​? - How can I use progress bar from Bootstrap in my Rails App? 如何使用Twitter中的Bootstrap样式表和Rails中的现有样式表而不会搞乱一切? - How do I use the Bootstrap stylesheet from Twitter with my existing stylesheet in Rails without messing up everything? 如何将Bootstrap-WYSIWYG集成到我的Rails应用程序中? - How can i integrate Bootstrap-WYSIWYG in my Rails app? 在我的Rails应用程序中使用Twitter Bootstrap,缺少标记 - Using Twitter Bootstrap in my Rails app, missing markup 如何使箭头键在Rails / Twitter-Bootstrap图像滑块(轮播)应用程序中工作? - How can I make the arrow keys work in a Rails/Twitter-Bootstrap image slider (carousel) app? 如何使用 ajax 在 Rails 6 应用程序中显示 Bootstrap 4 模式? - How can I use ajax to display Bootstrap 4 modal in Rails 6 app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM