多级菜单,活动链接CSS突出显示。 (Ruby on Rails)
网站结构:
/
/products
/products/design
/products/photo
/about
我希望看到当子项处于活动状态时,父菜单项也通过 CSS 突出显示。
“产品”也应该突出显示。)
(当“设计”或“照片”处于活动状态时, 将其用于子网址和简单网址:
<li class="<%= current_page?(:action => 'design') %>">
<%= link_to_unless_current 'Design', :design %>
</li>
对于“产品”检查应该类似于:
<%= current_page?(:action => 'products') ||
current_page?(:action => 'design') %> ||
current_page?(:action => 'photo') %>
但是三重||不对,而且变得复杂了。
我看到一个助手,就像这个:
def current(childs)
if current_page?(:action => childs)
@container = "active"
else
@container = "inactive"
end
end
由以下人员使用: <%= current(:photo) %>
那么,如何对“产品”、“设计”进行所有 3 个检查,“照片”在一个助手中?
并可以使用类似 <%= current(:products, :design, :photo) %>
Site structure:
/
/products
/products/design
/products/photo
/about
I want to see parent menu item also highlighted by CSS, when child is active.
(When 'design' or 'photo' is active 'products' should be highlighted too.)
I'm using this for child and simple urls:
<li class="<%= current_page?(:action => 'design') %>">
<%= link_to_unless_current 'Design', :design %>
</li>
For 'products' checking should be like:
<%= current_page?(:action => 'products') ||
current_page?(:action => 'design') %> ||
current_page?(:action => 'photo') %>
But triple || is not right, and it's become complicated.
I saw a helper, like this one:
def current(childs)
if current_page?(:action => childs)
@container = "active"
else
@container = "inactive"
end
end
Which is used by: <%= current(:photo) %>
So, how to put all my 3 checks for 'products', 'design', 'photo' in one helper?
And make possible to use something like <%= current(:products, :design, :photo) %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会重新创建轮子并使用 Rails menu-builder gem/像simple-navigation这样的插件。
这是导航和样式演示。
I wouldn't recreate the wheel and use a Rails menu-builder gem/plugin like simple-navigation.
Here's a demo of navigation and styling.