Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to invert the color of a png image on mouseover which is inside <a> tag?

I am working on bootstrap 3 where I'm creating a side navbar and want to place an image inside the anchor tag which is inside list tag. I want to invert the color of the image on mouseover, but its not happening. No effect takes place on mouseover. It will be great if anyone could help.

Here is my code:

HTML:

<ul class="nav nav-pills nav-stacked" data-role="panelbar" style="height: 600px;">
  <li>
      <a>
        <span class="glyphicon glyphicon-user glyph-width"></span>Group Name
        <span id="edit-img" class="img-span pull-right">
            <img src="images/glyphicons/Data-Edit.png">
        </span>
      </a>
   </li>
</ul>

CSS:

#edit-img :hover {
    -webkit-filter: invert(100%) !important;
}

I am not able to invert the color of Data-Edit.png on mousehover. Please help.

like image 861
Manali Avatar asked Mar 27 '14 06:03

Manali


People also ask

How do you invert the colors of an image in HTML?

CSS allows you to invert the color of an HTML element by using the invert() CSS function that you can pass to the filter property. Because the default color of the text is black, the color is inverted into white with filter: invert(100%) syntax.

How do I reverse the color of a PNG in CSS?

Use filter function to change the png image color. Filter property is mainly used to set the visual effect to the image. There are many property value exist to the filter function. filter: none|blur()|brightness()|contrast()|drop-shadow()|grayscale() |hue-rotate()|invert()|opacity()|saturate()|sepia()|url();


2 Answers

EDIT:

Check this DEMO

It's working in this case, should work in yours.


You'd have to apply it on the img tag

#edit-img:hover img{
    -webkit-filter: invert(100%) !important;
}
like image 183
Abhi Avatar answered Sep 21 '22 19:09

Abhi


Are you using a webkit browser? For me it works on -webkit-browsers, check the css at https://peterpaulvanham.nl/. If you want to make it work on Firefox e.g. use

-webkit-filter: invert(100%) !important; //* chrome, safari

filter: invert(100%) !important; //* e.g. firefox

You don't need "!important" per se b.t.w.

Is this an answer to your problem?

like image 44
Peter Paul Avatar answered Sep 20 '22 19:09

Peter Paul