简体   繁体   English

如何仅将navbar-fixed-top放在一页上?

[英]How to have the navbar-fixed-top only on one page?

I have a navbar that is fixed on the homepage but considering the other pages aren't nearly as long there is no need for it to be fixed. 我有一个固定在首页上的导航栏,但是考虑到其他页面的使用时间不长,因此无需进行固定。 How can I have the navbar only fixed on the homepage? 如何仅将导航栏固定在主页上?

You can do this by applying a class to the homepage's body element and then applying the position:fixed declaration within the context of that class. 您可以通过将一个类应用于首页的body元素,然后在该类的上下文中应用position:fixed声明来实现。 For example: the homepage body would be .homepage and then set .homepage .header {position:fixed;} . 例如:主页主体为.homepage ,然后设置.homepage .header {position:fixed;}

You can have the navbar in a partial which you include in a "homepage" layout. 您可以将导航栏放在包含在“主页”布局中的部分中。 You can then specify a layout for homepage only, defaulting to application.html.erb (or whatever) for your default layout on the rest of the pages. 然后,您可以仅指定首页的布局,其余页面的默认布局默认为application.html.erb(或其他)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM