jquery - 同时更改文本的颜色

标签 jquery html css

所以我花了很长时间试图弄清楚当我将鼠标悬停在导航上时如何更改背景颜色,然后我意识到我还需要更改现有文本的颜色以使其在导航悬停在上方。我不知道如何做到这一点。我的代码如下:

<DOCTYPE! html>
    <html>
        <head>
            <meta charset="utf-8">
            <meta http-equiv="X-UA-Compatible" content="IE=edge">
            <title>Jasmine Everett</title>
            <meta name="description" content="graphic designer just trying to get through life">
            <link rel="stylesheet" href="main.css">
            <link href="css/style.css" media="all" rel="stylesheet" »
          type="text/css" />
        </head>
        <body>
            <h2 align="center" class="change"> JASMINE EVERETT</h2>
            <h3 align="center" class="change"><em>Graphic Designer</em></h3>
                <ul class="nav">
                    <button><a  class="special" href="work.html">WORK</a></button> |
                    <button><a class="special" href="about.html">ABOUT</a></button> |
                    <button><a class="special" href="contact.html">CONTACT</a></button>
                </ul>
        </html>

CSS

.special{
    background: transparent;
    display: inline-block;
}

.special:before{
    background-color: transparent;
    transition; background-color 0.2s ease,opacity;
    content: '';
    top:0;
    bottom:0;
    left:0;
    right:0;
    z-index: -1;
    opacity: 0;
}
.special:hover:before{
    position:fixed;
    transition: background-color 0.2s ease, opacity;
    opacity: 1;
}
.special:hover:before{
    background-color: black;
}


button{border: none;
    background: white;
    color: black;
    padding: 10px;
    font-size: 18px;
    border-radius: 5px;
    position: relative;
    box-sizing: border-box;
    transition: all 500ms ease; 
}

button:hover {
    background: rgba(0,0,0,0);
    color: white;
    box-shadow: inset 0 0 0 3px white;
}

最佳答案

只需像这样在悬停时更改 color 属性即可。

.special:hover:before{
    background-color: black;
    color: #000000;
}

关于jquery - 同时更改文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48220495/

相关文章:

javascript - 我怎样才能使按钮固定在顶部并将内容折叠到其中

Jquery 悬停子项,否定父项悬停效果

javascript - jQuery 选择器错误?组合选择器 vs. 简单选择器 & find()

html - Actionmailer css 添加到整个应用程序

javascript - 阻止 Div 滚出 View

javascript - 无法找到 FullCalendar 日期弃用函数

javascript - Dojo:Div 标签问题

html - 向上滚动时如何使div元素位于导航栏下方

javascript - Jssor Slider 如何将箭头添加到缩略图图库

css - 如何从文件中删除所有空格