【问题标题】:changing font color on hovering the mouse over text将鼠标悬停在文本上时更改字体颜色
【发布时间】:2012-03-22 16:40:59
【问题描述】:

我对 css 不太了解,但我有点卡住了。我想在悬停时将字体颜色更改为浅蓝色。但是,我希望默认颜色为白色......我该怎么做?我现在所拥有的,已将默认文本更改为紫色.. 并带下划线:S 它确实将字体更改为蓝色,但在悬停时..

代码:

CSS:

    a:hover
{
    text-decoration:none;
    color: #B9D3EE; 
}

.navigationBar
{

    background: gray; 
    height: 50px; 
    width: 100%;
}
.menuOption
{
    width:143px;
    text-align: center;  
    position: static;   
    float:left;

}
#search
{
     position:relative; 
    font-weight: bold; 
    color: white;
    height: 27px;
    margin-left: 23px;
    left: 133px;
    top: -17px;
    margin-top: 1px;
}
#reports
{
    position:relative; 
   font-weight: bold; 
    color: white;
    height: 27px;
    margin-left: 23px;
    left: 34px;
    top: -16px;
    margin-top: 1px;
}
#addProject
{
     position:relative; 
     font-weight: bold; 
    color: #B9D3EE;
   height: 27px;
    margin-left: 23px;
    left: -542px;
    top: -18px;
    margin-top: 1px;
}
#editProject
{
     position:relative; 
    font-weight: bold; 
    color: white;
    height: 27px;
    margin-left: 23px;
    left: -611px;
    top: -18px;
    margin-top: 1px;
}
#more
{
     position:relative; 
    font-weight: bold; 
    color: white;
    height: 27px;
    margin-left: 23px;
    left: -66px;
    top: -15px;
    margin-top: 1px;
}

HTML:

<div class = "navigationBar">

            <asp:ImageButton ID="ImageButton1" runat="server" Height="18px" 
                ImageUrl="~/g.png" style="margin-left: 1012px; margin-top: 18px" 
                Width="23px" />

            <div id = "search" class = "menuOption" >
            <a href=""> Search </a>
            </div>

            <div id = "reports" class = "menuOption" >
            <a href=""> Reports </a>
            </div>

            <div id = "more" class = "menuOption" >
            <a href=""> More... </a>
            </div>

            <div id = "addProject" class = "menuOption" >
            <a href=""> Add Project </a>
            </div>


            <div id = "editProject" class = "menuOption" >
            <a href=""> Edit Project </a>
             </div>

</div>

【问题讨论】:

    标签: asp.net html css webforms


    【解决方案1】:
    a:link
    {
    text-decoration:none;
    color: #B9D3EE; 
    }
    a:visited
    {
    text-decoration:none;
    color: #B9D3EE; 
    }
    a:hover
    {
    text-decoration:none;
    color: #B9D3EE; 
    }
    a:active
    {
    text-decoration:none;
    color: #B9D3EE; 
    }
    

    另外,这里是关于伪类的参考,应该为您解决这个问题。

    http://www.w3schools.com/css/css_pseudo_classes.asp

    【讨论】:

    • 好的,谢谢,这行得通...但只是出于好奇...它是从哪里获得紫色带下划线的字体颜色/样式的?...
    • 紫色默认为“已访问”链接。我再次编辑了我的答案以显示所有 4 个伪元素。更改每种颜色以查看其效果。
    • 嗯...但是在点击任何东西之前就出现了紫色...?我的css中也没有任何“访问过”的代码......顺便感谢您的回复:)
    • 查看主题 stackoverflow.com/questions/4774022/… 了解有关跨浏览器的默认 CSS 的更多信息
    • 我认为如果您的浏览器之前访问过该链接,则可能会出现“已访问”状态。清除历史记录会将它们重置为“未访问”,但这不是一个很好的解决方案。您可以将“链接”和“已访问”设置为相同的颜色,这样您就看不到紫色了。
    【解决方案2】:

    类似于@Brett Wait,但更简洁

    a{
        text-decoration:none;
        color:#FFF;
    }
    
    a:hover
    {
        text-decoration:none;
        color: #B9D3EE; 
    }
    

    之所以是紫色,是因为默认超链接是蓝色的,但是当它们被访问时,就会变成紫色。在您的情况下,“”的 url 基本上是当前页面,也就是访问过的页面。 :)

    编辑删除不需要的伪类:h/t @yunzen

    【讨论】:

    • 您只需要a。它包含所有的伪类。访问过的只是不被否决,例如选择a:hover或a:link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多