How to show font awesome icon on hover

Sagar Singh

I have a link that is editable, if someone hover on that link there should be a fa fa-edit icon on hover

Here is the html code

<a href="#" class="btn" id="company_name" data-type="text" data-pk="3" data-name="company_name" data-title="Enter Company Name">Learn web programming</a>&nbsp;<i class="fa fa-pencil"></i>

I want to show fa fa-pencil icon on hover only

Pranav C Balan

Simple css can do the trick using adjacent sibling selector(+) and :hover. Also I've added slight variation in html that &nbsp; is wrapped by span for making symbol visible when it's hovers the icon.

a:hover +span+ i, /* when link is hovered select i */
a + span:hover+ i, /* when space after link is hovered select i */
a + span + i:hover { /* when icon is hovered select i */
  visibility: visible;
}

a +span+ i { /* in all other case hide it */
  visibility: hidden;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<a href="#" class="btn" id="company_name" data-type="text" data-pk="3" data-name="company_name" data-title="Enter Company Name">Learn web programming</a><span>&nbsp;</span><i class="fa fa-pencil"></i>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to show font awesome icon on hover

From Dev

How to change font awesome icon hover color?

From Dev

Rotating a font awesome icon on hover

From Dev

Change color when hover a font awesome icon?

From Dev

Assign Font Awesome icon to cursor on hover

From Dev

Font-Awesome Icon Hover Issue

From Dev

CSS3 rotation when hover a font awesome icon?

From Dev

Animate font-awesome stack to spin icon on hover

From Dev

CSS3 transition within Awesome Icon Font and Text Hover

From Dev

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

From Dev

How to position font awesome icon vertically

From Dev

How to toggle font awesome icon on click?

From Dev

How to position text over Font Awesome icon?

From Dev

How to add Font Awesome icon into <input> button?

From Dev

How to insert font awesome icon into text input?

From Dev

how use icon [Font-awesome] in WPF

From Dev

How to use Font Awesome icon in android application?

From Dev

How to position an Awesome Font Icon after a text

From Dev

How to hide / show icon with :hover

From Dev

Bootstrap 4 Collapse show state with Font Awesome icon

From Dev

Font Awesome Icon Alignment

From Dev

Font Awesome icon in React

From Dev

Font Awesome Icon Alignment

From Dev

How to use font icon (font-awesome) in XML selector

From Dev

How to change color of Font Awesome stacked icons on hover

From Dev

Replace Font Awesome with image on hover

From Java

How to center text vertically with a large font-awesome icon?

From Dev

How to hide the font awesome icon when the text next to it is not displayed?

From Dev

How to add a font-awesome icon to kendo UI MVC menu?

Related Related

HotTag

Archive