Ruby on Rails突出显示导航栏上的当前链接吗? [英] Ruby on Rails highlight current link on navigation bar?

查看:55
本文介绍了Ruby on Rails突出显示导航栏上的当前链接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何使用CSS在导航栏中突出显示当前链接吗?我不想使用控制器选项. 这是来自shared/menu.html.erb的代码:

Can anyone tell me how to highlight (with color) the current link on a navigation bar, using css? I don't want to use the controller option. Here is the code from shared/menu.html.erb:

 <div id = "navigation">

  <ul>

  <li id="menu"><%=link_to "Menu", menus_path, :class => "menunav"%></li>
 <li id="drink"><%=link_to " Drinks", drinks_path, :class => "drinknav"%> </li>

 </ul>

 </div>

推荐答案

有几种解决方法, 但是,如果您只追求简单的一种, 我建议在您的身体上增加一类.

There are a few approaches to this, but if you're after a simple one, I suggest adding a class to your body.

<body class="<%= params[:controller] %>_controller">
  ...
</body>

然后在CSS中,您可以执行以下操作.

Then in your css you can do the following.

body.menus_controller  #navigation a.menunav,
body.drinks_controller #navigation a.drinknav {
  background-color : yellow
  color : blue
}

如果要拆分多个页面,这可能会变得很复杂, 但是对于这个基本示例,应该没问题.

This can get complicated if you have multiple pages you want to split, but for this basic example it should be ok.

这篇关于Ruby on Rails突出显示导航栏上的当前链接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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