我制作了一个css按钮,但当我将鼠标悬停在按钮上时,我无法弄清楚如何将文字颜色更改为白色。
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}

<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
&#13;
当我添加颜色
时a.button1o:hover
它没有用。
我也尝试过:
答案 0 :(得分:1)
这是因为您在a
而不是span
尝试使用此颜色
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
color: #f44336;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
color: #fff;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
}
&#13;
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
&#13;
在上面的代码段中,我将color:#fff
添加到a.button1o:hover
,同时我将#f44336
添加到.button1o
另一种方法就是这样
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
background-color: #f44336;
transition: all 0.9s ease 0.1s;
color: #fff;
}
a.button1o:hover span {
transition: all 0.9s ease 0.1s;
color: #fff;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
&#13;
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
&#13;
答案 1 :(得分:1)
你错误地悬停了。你将鼠标悬停在.button1o类但是.button1o-text这个类重写.button1o这个颜色
请以这种方式输入您的代码
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
a.button1o:hover {
background-color: #f44336;
}
span.button1o-text:hover {
transition: all 0.9s ease 0.1s;
color:#fff;
}
答案 2 :(得分:0)
您有两种选择。清除选项是将color: #f44336
规则移出.button1o-text
并移至.button1o
,这将允许当前的悬停规则覆盖颜色。 (有没有理由你有一个单独的CSS规则?)
另一个选项是添加此悬停规则为文本着色:
.button1o:hover .button1o-text {
color: [hover color];
}
答案 3 :(得分:0)
您需要将hover属性添加到span元素。那就是:
a.button1o>span:hover {
color:white;
}
以下是问题
中的工作代码
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
}
a.button1o:hover {
color:white;
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
a.button1o>span:hover {
color:white;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}
<a class="button1o" href="" target="_blank">
<span class="button1o-text">Flat button</span>
</a>
答案 4 :(得分:0)
选中fiddle。
CODE
这应该可以按照您的意愿运行,告诉我是否有,谢谢。
a.button1o:hover{
background-color: #f44336;
transition: all 0.9s ease 0.1s;
}
a.button1o:hover .button1o-text{
color: #fff;
transition: all 0.9s ease 0.1s;
}
答案 5 :(得分:0)
你不需要span class =&#34; button1o-text ... 只需将设置集成到button1o类中,并将颜色:white添加到a.button1o:hover类。
<a class="button1o" href="" target="_blank">Flat button</a>
您可能还需要将text-decoration:none属性添加到button1o定义中。
答案 6 :(得分:-1)
您可以在父元素上使用:hover
选择器:
a.button1o:hover .button1o-text {
color: white;
}
此外,您应该将transition
属性放在第一个声明中,否则当用户停止悬停在按钮上时,您将失去转换。
.button1o {
background-color: transparent;
padding: 10px 15px;
margin-right: 15px;
border: 2px solid #f44336;
border-radius: 2px;
transition: all 0.9s ease 0.1s;
}
a.button1o:hover {
background-color: #f44336;
}
a.button1o:hover .button1o-text {
color: white;
}
.button1o-text {
font-size: .7em;
font-family: 'PT Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0;
color: #f44336;
}