将鼠标悬停在按钮上时文本颜色更改

2022-01-22 00:00:00 colors text hover css

我正在尝试更改悬停按钮内文本的颜色.

I am trying to change the color of the text inside the button on hover.

我可以让按钮本身改变颜色,但我希望按钮文本也改变颜色.

I can make the button itself change color, but I want the button text to change color too.

这是我当前的 css:

Here is my current css:

button,
input.button,
a.button,
input[type="submit"] {
background:#2e77ae;
background: -moz-linear-gradient(top, #5590bd, #2e77ae);
background: -webkit-linear-gradient(top, #5590bd, #2e77ae);
background: -o-linear-gradient(top, #5590bd, #2e77ae);
background: -ms-linear-gradient(top, #5590bd, #2e77ae);
background: linear-gradient(top, #5590bd, #2e77ae);
border-color:#2e77ae;}

button:hover,
input.button:hover,
a.button:hover,
input[type="submit"]:hover{

    background:#E6D332;
    background: -moz-linear-gradient(top, #E6D332, #E6D332);
    background: -webkit-linear-gradient(top, #E6D332, #E6D332);
    background: -ms-linear-gradient(top, #E6D332, #E6D332);
    background: linear-gradient(top, #E6D332, #E6D332);
    border-color:#2e77ae;}



button:focus,
input.button:focus,
a.button:focus,
input[type="submit"]:focus { 
    background-color:#E6D332;}

推荐答案

CSS 属性 color 一般控制元素中的文本颜色.在您的情况下,要更改悬停时的颜色,请使用 :hover 说明符;

The CSS property color controls the text color in elements generically. In your case, to change the color on hover, use the :hover specifier;

input[type = "submit"]:hover {
    color: #FF0000;
    //you can add more styles to be applied on hover
}

请注意,您也可以使用 rgb(x, y, z) 格式指定颜色.这里有一个小演示来说明:小链接.您可以在此处试用演示并查看源代码:另一个小链接.

Note that you can as well specify the color using the rgb(x, y, z) format. Here's a little demo to illustrate: little link. You can play around with the demo and view the source here: another little link.

希望对你有所帮助!

相关文章