Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-icons responsive size

How can I make react-icons icons size smaller for mobile? I understand pixel is not a good approach, but how should I do it?

import { FaSearch, FaFacebook, FaInstagram, FaUserCog, FaUserTimes } from "react-icons/fa";

    <FaSearch
        color="#023373"
        size="30px" />
like image 332
nanquim Avatar asked Sep 01 '25 20:09

nanquim


2 Answers

You can use @media query in your case. Add a class to your icon component and write media query for mobile device width.

<FaSearch color="#023373" className="SearchIcon" />

In your CSS, do this

.SearchIcon{
  font-size: 40px;
}

@media only screen and (max-width: 400px) {
  .SearchIcon {
    font-size: 20px;
  }
}

I created a working example using Stackblitz

Here's a list of all the @media queries for different device widths.

/* Extra small devices (phones, 600px and down) */
@media only screen and (max-width: 600px) {...}

/* Small devices (portrait tablets and large phones, 600px and up) */
@media only screen and (min-width: 600px) {...}

/* Medium devices (landscape tablets, 768px and up) */
@media only screen and (min-width: 768px) {...}

/* Large devices (laptops/desktops, 992px and up) */
@media only screen and (min-width: 992px) {...}

/* Extra large devices (large laptops and desktops, 1200px and up) */
@media only screen and (min-width: 1200px) {...}
like image 156
coderpc Avatar answered Sep 03 '25 11:09

coderpc


Another approach is to handle icon sizes on their wrappers. You can set the icon size to auto and change their parent size. You can do it on media queries or with any other method.

<IconContext.Provider value={{ size: 'auto' }}>
  <App />
</IconContext.Provider>
like image 22
Amir Avatar answered Sep 03 '25 10:09

Amir