简体   繁体   English

在悬停时更改链接颜色

[英]change link color on hover

For the links in the navigation bar On hover I need to give blue color but its not working. 对于导航栏中的链接在悬停时我需要提供蓝色但不起作用。 Instead it showing white color. 相反,它显示白色。

How to fix the issue? 如何解决这个问题?

Providing my code below. 在下面提供我的代码。

http://jsfiddle.net/7HzPd/ http://jsfiddle.net/7HzPd/

http://jsfiddle.net/7HzPd/embedded/result/ http://jsfiddle.net/7HzPd/embedded/result/

<div class="container">
    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
    </a>
    <a class="brand" href="#">
        <img alt="change" class="defieLogo" src="http://www.defie.co/designerImages/defie_logo_only.png">
    </a>
    <div class="nav-collapse collapse">
        <ul class="nav">
            <li class="active">
                <a href="/docs/examples/product.html">Product</a>
            </li>
            <li>
                <a href="/docs/examples/solution.html">Solutions</a>
            </li>
            <li>
                <a href="/docs/examples/service.html">Services</a>
            </li>
            <li class="iphonePartnerLink">
                <a href="/docs/examples/partner.html">Partners</a>
            </li>
            <li class="iphoneContactLink">
                <a href="/docs/examples/contact.html">Contact</a>
            </li>
        </ul>
        <ul class="nav" id="navSecond">
            <li class="">
                <a href="/docs/examples/partners.html">Partners</a>
            </li>
            <li>
                <a href="/docs/examples/contact.html">Contact</a>
            </li>
        </ul>
        <form class="navbar-form pull-right">
            <input class="span2" type="text" placeholder="Email">
            <input class="span2" type="password" placeholder="Password">
            <button type="submit" class="btn">Sign in</button>
        </form>
    </div>
    <!--/.nav-collapse -->
</div>

The only code I see that has hover is here: 我看到的唯一代码是悬停在这里:

.navbar-inverse .nav .active > a:hover{
       background-color: transparent;
}
.navbar-inverse .nav .active > a:hover{
      color: #14486b;
} 

First you should combine these elements, go through your css and clean it up some, no reason to have those separated. 首先,你应该结合这些元素,通过你的CSS并清理一些,没有理由将这些元素分开。

To your question, that is the only :hover elements I saw, in which case you are targetting any anchor with hover state that also has the .active class which is inside .nav class, inside .navbar-inverse class... You are targetting the :hover incorrectly, the active class applies to only one link at a time. 对于你的问题,这是唯一的:我看到的悬停元素,在这种情况下,你的目标是任何具有悬停状态的锚,它也有.active类,里面是.nav类,里面是.navbar-inverse class ...你是目标:不正确地悬停,活动类一次只应用于一个链接。

You should have something more like: 你应该有更多的东西:

.nav li a:hover {}

EDIT: 编辑:

Found the culprit further down. 发现了罪魁祸首。

Theres a hover state in bootstrap.css on line 4740 that is over-writing your styling. 在4740行的bootstrap.css中有一个悬停状态,它覆盖了你的样式。 Try putting a !important on the hover you put in, also make sure your style sheet is included beneath the bootstrap.css. 尝试在你放入的悬停上加上!important ,同时确保你的样式表包含在bootstrap.css下面。 You could also edit the bootstrap css directly. 您也可以直接编辑bootstrap css。

Doesn't this work? 这不行吗?

a:hover
{
background-color:blue;
} 

And just change a to something more specific if you want. 如果您愿意,只需将a更改为更具体的内容即可。

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

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