最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I change the icon color onHover with styling in react? - Stack Overflow

programmeradmin2浏览0评论

I have a few icons that have an initial style, styles.

<div className="w3-padding w3-xxlarge w3-text-grey">
                <a href='/About'><i className="fa fa-user-circle" style={styles.icons}></i></a>
                <a href='/Skills'><i className="fas fa-cog" style={styles.icons}></i></a>
                <a href='/Portfolio'><i className="far fa-eye" style={styles.icons}></i></a>
                <a href='/Contact'><i className="far fa-envelope" style={styles.icons}></i></a>
                </div>

I would like to add on hover styling such as change the color to white. I have the styling in the same file:

const styles = {
    icons: {
        width: '70%',
    }
}

I have a few icons that have an initial style, styles.

<div className="w3-padding w3-xxlarge w3-text-grey">
                <a href='/About'><i className="fa fa-user-circle" style={styles.icons}></i></a>
                <a href='/Skills'><i className="fas fa-cog" style={styles.icons}></i></a>
                <a href='/Portfolio'><i className="far fa-eye" style={styles.icons}></i></a>
                <a href='/Contact'><i className="far fa-envelope" style={styles.icons}></i></a>
                </div>

I would like to add on hover styling such as change the color to white. I have the styling in the same file:

const styles = {
    icons: {
        width: '70%',
    }
}
Share Improve this question edited Dec 16, 2019 at 4:27 Matt Croak 2,8982 gold badges22 silver badges43 bronze badges asked Dec 15, 2019 at 18:42 Chase LChase L 591 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

We don't have any actions inline style

We don't have any actions inline style like

:hover but you can use Js code

<div className="w3-padding w3-xxlarge w3-text-grey" >
    <a href='/About'}>
       <i className="fa fa-user-circle icon" style={styles.icons} 
      onMouseOver={({target})=>target.style.color='white'} 
      onMouseOut={(target)=>target.style.color='#00F'}>
       </i>
    </a>
</div>

or the best way : you use css file and import it in your css

.icon:hover { color:white}

and in your js file import it

 import './yourcssfile.css'
发布评论

评论列表(0)

  1. 暂无评论