Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding margin to font awesome icon in React

I use reactstrap in my project. I tried to add a margin to the font awesome icon in my react project, but it didn't work.

What am I missing?

<NavItem>
     <NavLink active href="/products"><FontAwesomeIcon className="mr-2" icon={faClone}></FontAwesomeIcon><span>Products</span></NavLink>
</NavItem>
like image 767
tolga Avatar asked Apr 01 '26 09:04

tolga


2 Answers

className won't work on a component, it only works on DOM elements. Try wrapping FontAwesomeIcon in a div/span

<NavItem>
     <NavLink active href="/products"><div className="mr-2"><FontAwesomeIcon icon={faClone}></FontAwesomeIcon><span>Products</span><div></NavLink>
</NavItem>
like image 128
Aman Kumar Avatar answered Apr 03 '26 00:04

Aman Kumar


I use the exact setup i-e reactstrap & react-fontawesome and this is what I use and it works perfect

<button>
<FontAwesomeIcon icon={faPlus} className="mr-3" /> Add
</button>

PS: Note that <FontAwesomeIcon icon={faIcon} /> is a self closing tag, and i think this is were you are getting this wrong.

like image 21
its4zahoor Avatar answered Apr 02 '26 23:04

its4zahoor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!