简体   繁体   English

真棒字体图标,悬停时在图标(文本)中间更改颜色

[英]Font-Awesome Icons, Change Color In The Middle of The Icon (The Text) On Hover

This question is pretty similar to one that's already been asked , except that I'm trying to change the text-color of the icon only when you hover over it. 这个问题与已经提出的问题非常相似,除了我只在将鼠标悬停在图标上时才尝试更改图标的文本颜色。

Right now, hovering over the icons looks like this: 现在,将鼠标悬停在图标上看起来像这样:

在此处输入图片说明

Although the color is correct, you can see that it's extending outside of the icon. 尽管颜色是正确的,但是您可以看到它正在图标之外延伸。 Here's my HTML: 这是我的HTML:

<div id="social-media-container">
    <li class="social-media">
        <a class="fa fa-facebook-square"
                       href="https://www.facebook.com/gatewaywebdesign18/?ref=aymt_homepage_panel"
                       target="blank"></a>
    </li>
    <li class="social-media">
        <a class="fa fa-twitter-square"
                       href="https://www.twitter.com/gatewaywebdesign18/?ref=aymt_homepage_panel"
                       target="blank"></a>
    </li>
    <li class="social-media">
        <a class="fa fa-linkedin-square"
                       href="https://www.linkedin.com/gatewaywebdesign18/?ref=aymt_homepage_panel"
                       target="blank"></a>
     </li>
</div>  

And my CSS: 而我的CSS:

#social-media-container {
position: relative;
float: right;
margin-top: 10px;
}

.social-media a {
color: #ffffff;
display: table-cell;
font-size: 25px;
padding: 0px;
}

.social-media a:hover {
text-decoration:none;
background-color: #1971b9;
border-radius: 5px;
}

I've tried to adjust the border radius on .social-media a:hover but it's still extending past the icon: 我试图调整.social-media a:hover上的边框半径,但是它仍延伸到图标之外:

在此处输入图片说明

I've also tried to adjust the padding of .social-media a:hover , but no effect. 我也尝试过调整.social-media a:hover的填充,但没有效果。 This website is live here: http://nowordpress.gatewaywebdesign.com/ . 该网站位于此处: http : //nowordpress.gatewaywebdesign.com/ I tried to create a JSFiddle but it looks like it won't load the external resource (font-awesome.min.css). 我试图创建一个JSFiddle,但看起来它不会加载外部资源(font-awesome.min.css)。 Any suggestions? 有什么建议么? Thanks. 谢谢。

EDIT : Link to working JS Fiddle with loaded font-awesome stylesheet. 编辑 :链接到工作的JS小提琴与加载的字体真棒样式表。

This is also solvable by using Font Awesome's stack system, just like in the link you mentioned: 也可以通过使用Font Awesome的堆栈系统来解决,就像您提到的链接中一样:

<a href="https://www.facebook.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank">
  <span class="fa-stack icon-facebook">
    <i class="fa fa-square fa-stack-1x outside"></i>
    <i class="fa fa-facebook fa-stack-1x inside"></i>
  </span>
</a>

And the CSS: 和CSS:

.social-media a .fa-stack {
  font-size: 13px;
}

.social-media a .outside {
  font-size: 25px;
}

.social-media a .inside {
  font-size: 17px;
  color: #1B3764;
}

.social-media a:hover .inside {
  color: #1971b9;
}

 #social-media-container { position: relative; margin-top: 10px; background-color: #1B3764; } .social-media a { color: #ffffff; display: table-cell; font-size: 25px; padding: 0px; } .social-media a .fa-stack { font-size: 13px; } .social-media a .outside { font-size: 25px; } .social-media a .inside { font-size: 17px; color: #1B3764; } .social-media a:hover .inside { color: #1971b9; } 
 <link href="http://netdna.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet" /> <div id="social-media-container"> <li class="social-media"> <a href="https://www.facebook.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank"> <span class="fa-stack icon-facebook"> <i class="fa fa-square fa-stack-1x outside"></i> <i class="fa fa-facebook fa-stack-1x inside"></i> </span> </a> </li> <li class="social-media"> <a href="https://www.twitter.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank"> <span class="fa-stack icon-twitter"> <i class="fa fa-square fa-stack-1x outside"></i> <i class="fa fa-twitter fa-stack-1x inside"></i> </span> </a> </li> <li class="social-media"> <a href="https://www.linkedin.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank"> <span class="fa-stack icon-linkedin"> <i class="fa fa-square fa-stack-1x outside"></i> <i class="fa fa-linkedin fa-stack-1x inside"></i> </span> </a> </li> </div> 

This will change only the inner color. 这将仅更改内部颜色。

<a class="fa fa-facebook-square" href="https://www.facebook.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank"></a>

to

<a class="" href="https://www.facebook.com/gatewaywebdesign18/?ref=aymt_homepage_panel" target="blank">
  <i class="fa fa-facebook-square" style="
    color: #337ab7;
"></i>
</a>

And you can give the < a > tag's background color to transparent. 您可以将<a>标记的背景色设置为透明。 After that, you can give < i > tags color as your reqeust. 之后,您可以为<i>标签添加颜色。

.social-media a:hover {
text-decoration:none;
background-color: #1971b9;
border-radius: 5px;
}

to

.social-media a i:hover {
text-decoration:none;
background-color: #1971b9;
border-radius: 5px;
}

or you can use this 或者你可以用这个

            <span class="fa-stack fa-lg">
              <i class="fa fa-square fa-stack-2x"></i>
              <i class="fa fa-facebook fa-stack-1x"></i>
            </span>

you can modify the icon size by modifying font size. 您可以通过修改字体大小来修改图标大小。

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

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