Using CSS to give a black icon another color

38,512

Solution 1

Your code isn't working because the src attribute is being used to show up the black version on top of the orange version. You will be able to get the desired result only with CSS, this way:

.dashboard-buttons .sessions .img { width: 60px; height: 60px; background-color: #C60; }
.dashboard-buttons .sessions .img { -webkit-mask-image: url('http://i.stack.imgur.com/gZvK4.png'); }

Here is the changed HTML snippet:

<div class="dashboard-buttons">
   <a href="sessions.php" class="sessions">
       <div class="img"></div>
       <span>Sessions</span>
   </a>
</div>​

And here is a working sample of it.

Solution 2

Try use background image for your image, then use another div inside the first one to apply the alpha

    <style type="text/css">
        #image{background-image:url(/img/2012-05-24_1834.png);width:400px;height:400px;}
        #image #image_mask{background-color:red;width:400px;height:400px;opacity:0.4;filter:alpha(opacity=40); /* For IE8 and earlier */}
    </style>

</head>


<body>

        <div id="image">
                <div id="image_mask"></div>
       </div>
</body>

sry for not using your code, i started to work in your awnser before you posted it

Share:
38,512
Patr01
Author by

Patr01

We consult and build stuff out of Toronto!

Updated on May 09, 2020

Comments

  • Patr01
    Patr01 about 4 years

    I saw some apps where even though a black icon was included, some how the app used CSS to convert the icon into a different colour. I can't seem to repeat this process

    Here's my back.css file:

    .dashboard-buttons a {
        width: 80px; 
        height: 80px; 
        border: 1px solid #ccc; 
        margin: 0px 5px; 
        display:inline-block;
        border-radius: 10px;
        background:white; 
        text-decoration:none;
       -moz-box-shadow: inset 0 0 15px rgba(0,0,0, 0.25);
       -webkit-box-shadow: inset 0 0 15px rgba(0,0,0, 0.25);
    }
    .dashboard-buttons a:hover {
        text-decoration:underline;
    }
    .dashboard-buttons span, 
    .dashboard-buttons img {
        display:inline; 
        font-size: 12px; 
        font-weight:bold;
    }
    
    .dashboard-buttons .sessions img { 
        background-color:#C60; 
    }
    .dashboard-buttons .sessions img {
        -webkit-mask-image:url(mobile/images/calendar2.png)
    }
    

    And the html code looks like this:

    <!DOCTYPE html>
    <html lang="en">
        <head>
            <link rel="stylesheet" type="text/css" href="back.css" />
             <title>West</title>
        </head>
        <body>
            <div class="dashboard-buttons">
                <a href="sessions.php" class="sessions">
                    <img src="mobile/images/calendar2.png">
                    <span>Sessions</span>
                </a>
            </div>
        </body>
    </html>
    

    But it's not working in my chrome browser. Am i missing something?

    Additional notes I only need to support modern webkit browsers. Don't need to worry about IE or anything else.

    I posted my code here http://jsfiddle.net/ZnbF3/ . First time using jsfiddle, hopefully it's working? If not, just copy the html file and css file i already posted above. I have the calendar2.png attached to this question.

    enter image description here

  • Budianto IP
    Budianto IP almost 8 years
    Good idea on that opacity
  • Goor Lavi
    Goor Lavi over 5 years
    perfect! Thank u.