Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change Google Material Icon on hover with only html/css

I would like to change a Google Material Icon (the actual icon itself) on a button hover. I would like to do this with only HTML and CSS. I would like it to go from the 'plus' icon to something like a 'check' icon, specifically, using the 'done' icon. Codepen below. Thanks

.material-icons.md1 {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 33px;
    margin-top: 12px;
}
.btnwrap {
    position: fixed;
    z-index: 2;
    height: 60px;
    width: 300px;
    background-color: #074fb2;
    font-size: 20px;
    display: block;
    text-align: center;
    vertical-align: middle;
    line-height: 60px;
    color: #fff;
    border-radius: 50px;
    cursor: pointer;
}
.btntext1 {
    position: absolute;
    left:85px; 
    transition: all .1s;
}
.btntext2 {
    position: absolute;
    width: 100%;
    transition: all .2s;
    opacity: 0;
}
.innerbtn {
    z-index: 1;
    position: relative;
    float: left;
    height: 56px;
    width: 56px;
    background-color: #3e81dc;
    border-radius: 50px;
    display: inline-block;
    margin-top: 2px;
    margin-left:2px; 
    transition: all 1s;
}
.btnwrap:hover .btntext1 {
    opacity: 0;
    transition: all .5s;
}
.btnwrap:hover .btntext2 {
    opacity: 1;
    transition: all .5s;
}
.btnwrap:hover .innerbtn {
    margin-left: 242px;
}
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
  rel="stylesheet">
<div id="button1" class="btnwrap" title="download_btn">
<div class="innerbtn"><i class="material-icons md1">add</i></div> 
<div class="btntext2">Click Now</div>
<div class="btntext1">Download for FREE</div>
</div>

https://codepen.io/anon/pen/YYEXYy

like image 672
scott.schaffer Avatar asked Jun 09 '17 16:06

scott.schaffer


People also ask

How do I use the Google material icon in HTML?

To embed Google Icons in your HTML web pages you have to add the link of material-icons font library in the <head> section of your HTML file and then add the class material-icons in the <i> or <span> tag of the <body> section along with the name of the icon.

Can I change icon color CSS?

To change the color of the icons, simply add or change the “color” property in the CSS. So to change the color of the icons to red in the above example, add “color:red” to the . searchlinks a::after pseudo element.


2 Answers

So Im answering my own question here.. Leave the html empty, add the 'content' with ':before' in CSS, and then change that ':before' with the hover state.. see the forked Codepen:

<i class="material-icons md1" style="margin-top: 12px;"></i></div> 

.material-icons.md1::before{
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 33px;
    content:"add"; 
}

.btnwrap:hover .material-icons.md1::before{
    content:"done"; 
}

https://codepen.io/anon/pen/aEVOEr

like image 127
scott.schaffer Avatar answered Oct 30 '22 02:10

scott.schaffer


HTML

<i class="material-icons md1"></i>

CSS

.material-icons.md1::before{
    content:"add"; 
}

.material-icons.md1:hover::before{
    content:"remove"; 
}

https://codepen.io/Funny0Frank/pen/RMYBvQ

like image 29
Pylinux Avatar answered Oct 30 '22 02:10

Pylinux