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?
我有一个固定在主页上的导航栏,但考虑到其他页面的时间差不多,不需要修复它。如何才能在主页上修复导航栏?
2 个解决方案
#1
1
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. For example: the homepage body would be .homepage
and then set .homepage .header {position:fixed;}
.
您可以通过将类应用于主页的body元素,然后在该类的上下文中应用position:fixed声明来实现此目的。例如:主页正文为.homepage,然后设置.homepage .header {position:fixed;}。
#2
0
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(或其他),以用于其余页面上的默认布局。
#1
1
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. For example: the homepage body would be .homepage
and then set .homepage .header {position:fixed;}
.
您可以通过将类应用于主页的body元素,然后在该类的上下文中应用position:fixed声明来实现此目的。例如:主页正文为.homepage,然后设置.homepage .header {position:fixed;}。
#2
0
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(或其他),以用于其余页面上的默认布局。