突出显示菜单中的选项卡

突出显示菜单中的选项卡

本文介绍了突出显示菜单中的选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ul 的菜单

I have a menu which is a ul

Home | Calendar | Settings

我想突出显示(通过 css 类)菜单中选定的选项卡.

I want to highlight (via a css class) the selected tab in the menu.

某些链接(主页和日历)也有子选项

Some links (Home and Calendar) also have subselections

Home | *Calendar* | Settings
-------------------------
Add event | Edit event

当然,选择编辑事件时,日历仍应突出显示.

Ofcourse when edit event is selected, Calendar should still be highlighted.

我怎样才能最好地使用 rails 和 css 来解决这个问题?

how can I best approach this using rails and css?

谢谢

推荐答案

最简单的方法是检查正在使用哪个控制器.我编造了控制器名称,因此您当然可以用正确的名称替换home"、calendar"和settings".

The simplest way would be to check which controller is being used. I made up controller names, so of course you would replace 'home', 'calendar', and 'settings' with the correct names.

<ul>
  <li class="<%= "highlighted" if params[:controller] == "home" %>">Home</li>
  <li class="<%= "highlighted" if params[:controller] == "calendar" %>">Calendar</li>
  <li class="<%= "highlighted" if params[:controller] == "settings" %>">Settings</li>
</ul>

这篇关于突出显示菜单中的选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:18