简体   繁体   English

鼠标悬停时更改字体真棒图标的颜色

[英]Change font-awesome icon color when mouse over

I have icons inside the input text box. 我在输入文本框中有图标。 when mouse over the icons I want to change the color of icons.and I tried but that won't work. 当我将鼠标悬停在图标上时,我想更改图标的颜色。我尝试了一下,但是那不起作用。

Below my code. 在我的代码下面。

<div class="row">
        <span class="fa fa-envelope" style="position: absolute; top: 10px; left: -5px; color: black"></span>
        <span class="fa fa-file" style="position: absolute; top: 10px; left: 20px; color: black"></span>
        <span class="fa fa-calendar" style="position: absolute; top: 10px; left: 42px; color: black"></span>
        <span class="fa fa-bar-chart" style="position: absolute; top: 10px; left: 65px; color: black"></span>
        <input id="Text1" class="col-md-8" type="text" placeholder="Send Message" style="padding: 30px; border: 1px solid #aaa />
    </div>

I need solution for that problem. 我需要解决该问题的方法。

Your use of inline styles means that you have to use !important to override the default state of black : 使用内联样式意味着必须使用!important覆盖black的默认状态:

 span:hover { color: green !important; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/> <div class="row"> <span class="fa fa-envelope" style="position: absolute; top: 10px; left: -5px; color: black"></span> <span class="fa fa-file" style="position: absolute; top: 10px; left: 20px; color: black"></span> <span class="fa fa-calendar" style="position: absolute; top: 10px; left: 42px; color: black"></span> <span class="fa fa-bar-chart" style="position: absolute; top: 10px; left: 65px; color: black"></span> <input id="Text1" class="col-md-8" type="text" placeholder="Send Message" style="padding: 30px; border: 1px solid #aaa /> </div> 

A better solution might look something like this: 更好的解决方案可能如下所示:

 .fa { position: absolute; top: 10px; color: black; } .fa:nth-child(1) { left: -5px; } .fa:nth-child(2) { left: 20px; } .fa:nth-child(3) { left: 42px; } .fa:nth-child(4) { left: 65px; } .fa:hover { color: green; } 
 <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" /> <div class="row"> <span class="fa fa-envelope"></span> <span class="fa fa-file"></span> <span class="fa fa-calendar"></span> <span class="fa fa-bar-chart"></span> <input id="Text1" class="col-md-8" type="text" placeholder="Send Message" style="padding: 30px; border: 1px solid #aaa" /> </div> 

I'd rather suggest removing the inline color: black and replace it with css styles. 我宁愿建议删除内联color: black ,并用css样式替换。 Avoid using !important when you can, right? 尽量避免使用!important对吧?

 .fa{ color: black } .fa:hover{ color:blue; } 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css" rel="stylesheet"/> <div class="row"> <span class="fa fa-envelope" style="position: absolute; top: 10px; left: -5px;"></span> <span class="fa fa-file" style="position: absolute; top: 10px; left: 20px;"></span> <span class="fa fa-calendar" style="position: absolute; top: 10px; left: 42px;"></span> <span class="fa fa-bar-chart" style="position: absolute; top: 10px; left: 65px;"></span> <input id="Text1" class="col-md-8" type="text" placeholder="Send Message" style="padding: 30px; border: 1px solid #aaa /> </div> 

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

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