简体   繁体   English

如何在 Angular 中使用 CSS 设置 FontAwesome 图标的大小?

[英]How do you set the size of FontAwesome icon using CSS in Angular?

Per FontAwesome Usage Guide, you set the size of icons like so:根据 FontAwesome 使用指南,您可以像这样设置图标的大小:

1. <fa-icon [icon]="['far', 'coffee']" [classes]="['toolbar-icon']" size="2x"></fa-icon>
2. <fa-icon [icon]="['far', 'coffee']" [classes]="['toolbar-icon']" transform="grow-8"></fa-icon>

The above methods work in the component view template.上述方法在组件视图模板中起作用。 However, I would like my icons to be responsive and would like it to resize in response to screen size changes.但是,我希望我的图标具有响应性,并希望它能够根据屏幕大小的变化调整大小。

I tried the following CSS settings:我尝试了以下 CSS 设置:

#main-toolbar {
    background-color: rgb(165, 42, 42);

    // ... othe entries

    @media only screen and (min-width:480px){
        fa-icon {
            color: white;
            padding: 0px 64px;
            size: "lg";
            // transform: "grow-8";
        }      
      }
      
      @media only screen and (max-width:680px){
        fa-icon {
            color: yellow;
            padding: 0px 16px;
            size: "sx";
            // transform: "grow-2";
        }      
      }
}// #main-toolbar

The color and padding changes so the CSS is working.颜色和填充发生变化,因此 CSS 正在工作。 However, both size and transform does not work and are ignored.但是, sizetransform都不起作用并被忽略。 Also, setting the size of the icon in the CSS even without media query does not work.此外,即使没有媒体查询,也无法在 CSS 中设置图标的大小。

Is there a way to set the size of the icon through CSS?有没有办法通过 CSS 设置图标的大小?

I am using FontAwesome v6.1.1 in Angular v14.0.4.我在 Angular v14.0.4 中使用 FontAwesome v6.1.1。 Any help would be greatly appreciated.任何帮助将不胜感激。 Thanks in advance.提前致谢。

Creating an answer just in case other people find this question and doesn't look in the comments.创建一个答案,以防其他人发现此问题并且不查看评论。

Since you style markup, you can use font-size to set the size of FontAwesome icons.由于您设置了标记样式,因此您可以使用font-size来设置 FontAwesome 图标的大小。

fa-icon {
  font-size: 20px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM