简体   繁体   English

Foundation 4不将悬停类应用于顶部菜单

[英]Foundation 4 not applying hover class to top menu

I'm trying to create a nav bar using Foundation 4. I want to make the link text change color when hovering over it. 我正在尝试使用Foundation 4创建导航栏。我想使链接文本悬停在其上时更改颜色。

I set the 我设定

$topbar-link-color-hover 

variable to the color I want and in the CSS I see the color is added to 变量到我想要的颜色,在CSS中我看到颜色被添加到

.top-bar-section ul li.hover > a

However, it doesn't work. 但是,它不起作用。 The CSS makes it seem like JS should be adding a hover class to the menu item, but it's not. CSS使得JS应该在菜单项上添加一个悬浮类,但事实并非如此。

If I change the line to 如果我将行更改为

.top-bar-section ul li:hover > a

I get the effect I want. 我得到了想要的效果。 I would like to do this the correct way though. 我想以正确的方式来做。

My HTML for the menu looks like this 我的菜单HTML看起来像这样

<nav class="top-bar">
    <ul class="title-area">
        <!-- Title Area -->
        <li class="name">
        </li>
        <!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
        <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
    </ul>
    <section class="top-bar-section">
        <ul class="left">
            <li>
                <%= link_to "Link 1", '#' %>
            </li>
            <li>
                <%= link_to "Link 2", '#' %>
            </li>
            <li>
                <%= link_to "Link 3", '#' %>
            </li>
            <li>
                <%= link_to "Link 4", '#' %>
            </li>
        </ul>
    </section>
</nav>

I am also using Rails 4. 我也在使用Rails 4。

Is this not what $topbar-link-color-hover is intended for, or am I missing something in my code? 这不是$ topbar-link-color-hover的目的,还是我的代码中缺少什么?

I should also note that JS seems to be working because the menu will expand properly (when in mobile view). 我还应该注意,JS似乎可以正常工作,因为菜单可以正确展开(在移动视图中)。

Ok, your JS is not working at all. 好的,您的JS根本无法工作。

As you're pointing, when you add .top-bar-section ul li:hover > a, you're giving it the behavior via CSS. 正如您所指出的那样,当您添加.top-bar-section ul li:hover> a时,您通过CSS赋予了它行为。

Foundation JS adds the class .hover when hovering over the item menu, from docs ( http://foundation.zurb.com/docs/components/topbar.html , see "Advance part"), your markup should looks like: 将鼠标悬停在项目菜单上时,Foundation JS会从文档( http://foundation.zurb.com/docs/components/topbar.html ,请参阅“高级部分”)中添加类.hover,您的标记应类似于:

<section class="top-bar-section">
<!-- Right Nav Section -->
<ul class="right">
  <li class="has-dropdown">         
    <a href="#">Right Button with Dropdown</a>
    <ul class="dropdown">
      <li><a href="#">First link in dropdown</a></li>
    </ul>
  </li>
</ul>

When you do it and you inspect the code, you may see that hover class is added, and so the CSS rule for hover class (a.hover) is applied. 当您执行此操作并检查代码时,您可能会看到添加了悬停类,因此适用了悬停类的CSS规则(a.hover)。

Just guessing, if you rewrite your menu as... 只是猜测,如果您将菜单重写为...

<section class="top-bar-section">
    <ul class="left">
        <li class="has-dropdown not-click">
            <a href="#">Title for dropdown...</a>
            <ul class="dropdown">

        <li>
            <%= link_to "Link 1", '#' %>
        </li>
        <li>
            <%= link_to "Link 2", '#' %>
        </li>
        <li>
            <%= link_to "Link 3", '#' %>
        </li>
        <li>
            <%= link_to "Link 4", '#' %>
        </li>


            </ul>
        </li>
    </ul>
</section>

... it'll work because you'd have added the missing markup. ...之所以会成功,是因为您已经添加了缺少的标记。 Hope it helps! 希望能帮助到你!

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

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