Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing font size doesn't work with SVGR and Tailwind #13

Open
da-kicks-87 opened this issue Jan 12, 2023 · 7 comments
Open

Changing font size doesn't work with SVGR and Tailwind #13

da-kicks-87 opened this issue Jan 12, 2023 · 7 comments

Comments

@da-kicks-87
Copy link

da-kicks-87 commented Jan 12, 2023

Hello,

I am able to import the svgs as React components into my Next.js App via SVGR. They render in the browser.

I am having problem changing the size of the icons by font size.

I have added this to my global css to change the icons by font size:

svg {
    width: 1rem;
    height: 1rem;
    fill: currentColor;
  }

I then call the components with Tailwindcss class like this:
<Face className="text-8xl" />

In the browser the Face icon gets cropped and is not the correct size.

Any ideas why?

@marella
Copy link
Owner

marella commented Jan 13, 2023

Hi,

You should use em not rem to change size by font size as mentioned here:

svg {
  width: 1em;
  height: 1em;
  fill: currentColor;
}

@da-kicks-87
Copy link
Author

da-kicks-87 commented Jan 15, 2023

Hi yes, you are right, using em units should be used in order to change its' size by font size. I am more accustomed to using mostly rem units because Tailwind and other CSS frameworks use them.

Anyways I have also tried with em units as in your example. More of the icon is shown, but still a cropping problem.

React compoents with Tailwind font classes.

<Face className="text-3xl" /> <Star className="text-3xl" />
Screenshot of the crop:

Screenshot 2023-01-15 123100

Could it be that svg themselves are not optimized?

@marella
Copy link
Owner

marella commented Jan 16, 2023

Are you using the latest version of material-symbols? Similar issue used to be present in older versions (< 0.4.0) due to SVGs missing viewBox property.

@da-kicks-87
Copy link
Author

I have installed the material-symbols/svg-400 package. I only need the svgs. It is the latest version 0.4.2

I have inspected the react rendered svgs, they don't have the viewBox property.

@da-kicks-87
Copy link
Author

I have compared the SVG code from this repo the the SVGs that are rendered on my app. In this repo the SVGs do have the viewBox attribute, but when they are rendered on my App with SVGR they are missing the viewBox attribute.

This would be an issue with SVGR then?

@marella
Copy link
Owner

marella commented Mar 12, 2023

Sorry for the late response. I think SVGR uses SVGO under the hood which removes viewBox by default. You can disable removeViewBox plugin in your SVGO config.
Please see SVGO README and this issue for more info.

@MaKTaiL
Copy link

MaKTaiL commented Sep 14, 2023

I'm having a hard time adjusting the size of these icons. I changed to 'em' instead of 'rem' and it is still not working. I don't know what to do honestly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants