如何缩放 react-icons 包中的(大)字体真棒图标
how to scale (large) font-awesome icons from the react-icons package
我正在使用 marvelouse react-icons 包 (http://gorangajic.github.io/react-icons/fa.html),特别是 font awesome 包。
如果这不是react,那么I would just add an attribute to the tag,比如:
<i class="fa fa-camera-retro fa-5x"></i>
但是,如果我将 fa-5x 添加到 FaFolderOpen 标签,它不会执行任何操作。如您所见,我正在使用 react-bootstrap,并将图标放置为一个按钮(它应该是一个块)吗?
我不得不相信之前有人问过这个问题,但我没有通过搜索找到它。
这是它的样子,我想要更大的:
const React = require('react')
import { Form, FormControl, FormGroup, ControlLabel, Col, Button, Tooltip, OverlayTrigger } from 'react-bootstrap'
import FaFolderOpen from 'react-icons/lib/fa/folder-open'
import FaFileCodeO from 'react-icons/lib/fa/file-code-o'
import FaFolderOpen from 'react-icons/lib/fa/folder-open'
import FaFileCodeO from 'react-icons/lib/fa/file-code-o'
<Button type="button" bsStyle="success" block onClick={(e) => folderChooser(e)}>
<FaFolderOpen />
</Button>
如果你想要 5 倍的图标大小,你需要将它传递给反应 class 作为 size
// Font awesome pixel sizes relative to the multiplier.
// 1x - 14px
// 2x - 28px
// 3x - 42px
// 4x - 56px
// 5x - 70px
<FaFolderOpen size={70} />
如果你注意到它每次跳 14
from the github readme 它显示所有内容都被内联覆盖。它渲染一个 svg 所以你不能使用 5x
你必须使用像素大小
编辑
几年后回到这个问题上来,使用较新版本的 FontAwesome/ReactIcons 处理不同大小的推荐方法是使用他们的图标提供程序,该提供程序利用 React 上下文 API。这需要 React v16.3+
import { IconContext } from "react-icons";
<IconContext.Provider value={{ className: "shared-class", size: 70 }}>
<>
<FaFolder />
<FaBeer />
</>
</IconContext.Provider>
你可以使用这个:
<FaFolderOpen size="4x" />
在reactjs中你可以使用size = 'with your preferred size which be from sm to lg or 1x to 10x'
这是 react 中 font awesome 5 的示例
<FontAwesomeIcon icon={faBars} size = '10x'/>
如果您需要同时设置多个图标的样式,可以将它们包装到 IconContext.Provider。
<IconContext.Provider value={{color: 'navy', size: 42}}>
<FaFacebook />
<FaGithub />
<FaLinkedin />
</IconContext.Provider>
一种不是很明确的方法来自docs(接近@Raimo Haikari):
App.jsx
import {IconContext} from "react-icons";
import { FaBeer } from 'react-icons/fa';
import './App.css'
class App extends component {
return (
<div>
<IconContext.Provider value={{ className="myReact-icons"}}>
<FaBeer />
</IconContext.Provider>
</div>);
}
App.css
.myreact-icons {
color: red;
height: 2em;
}
默认大小为 1em。您可以这样更改它:
import { FcSurvey } from 'react-icons/fc';
<FcSurvey size={'2em'} />
我有一位设计师给我的像素大小并不总是对应于 FontAwesome 的大小选项之一。所以我正在设置 CSS 高度。
<FontAwesomeIcon icon={faBars} style={{ height: "20px" }} />
React-Icons 有一个叫做 size 的属性,可以用来设置任何你想要的尺寸。
从 react-icon 库中导入 react-icon 后,您可以轻松地做这样的事情。
<FaUsers size={'4rem'} />
我正在使用 marvelouse react-icons 包 (http://gorangajic.github.io/react-icons/fa.html),特别是 font awesome 包。
如果这不是react,那么I would just add an attribute to the tag,比如:
<i class="fa fa-camera-retro fa-5x"></i>
但是,如果我将 fa-5x 添加到 FaFolderOpen 标签,它不会执行任何操作。如您所见,我正在使用 react-bootstrap,并将图标放置为一个按钮(它应该是一个块)吗?
我不得不相信之前有人问过这个问题,但我没有通过搜索找到它。
这是它的样子,我想要更大的:
const React = require('react')
import { Form, FormControl, FormGroup, ControlLabel, Col, Button, Tooltip, OverlayTrigger } from 'react-bootstrap'
import FaFolderOpen from 'react-icons/lib/fa/folder-open'
import FaFileCodeO from 'react-icons/lib/fa/file-code-o'
import FaFolderOpen from 'react-icons/lib/fa/folder-open'
import FaFileCodeO from 'react-icons/lib/fa/file-code-o'
<Button type="button" bsStyle="success" block onClick={(e) => folderChooser(e)}>
<FaFolderOpen />
</Button>
如果你想要 5 倍的图标大小,你需要将它传递给反应 class 作为 size
// Font awesome pixel sizes relative to the multiplier.
// 1x - 14px
// 2x - 28px
// 3x - 42px
// 4x - 56px
// 5x - 70px
<FaFolderOpen size={70} />
如果你注意到它每次跳 14
from the github readme 它显示所有内容都被内联覆盖。它渲染一个 svg 所以你不能使用 5x
你必须使用像素大小
编辑
几年后回到这个问题上来,使用较新版本的 FontAwesome/ReactIcons 处理不同大小的推荐方法是使用他们的图标提供程序,该提供程序利用 React 上下文 API。这需要 React v16.3+
import { IconContext } from "react-icons";
<IconContext.Provider value={{ className: "shared-class", size: 70 }}>
<>
<FaFolder />
<FaBeer />
</>
</IconContext.Provider>
你可以使用这个:
<FaFolderOpen size="4x" />
在reactjs中你可以使用size = 'with your preferred size which be from sm to lg or 1x to 10x'
这是 react 中 font awesome 5 的示例
<FontAwesomeIcon icon={faBars} size = '10x'/>
如果您需要同时设置多个图标的样式,可以将它们包装到 IconContext.Provider。
<IconContext.Provider value={{color: 'navy', size: 42}}>
<FaFacebook />
<FaGithub />
<FaLinkedin />
</IconContext.Provider>
一种不是很明确的方法来自docs(接近@Raimo Haikari):
App.jsx
import {IconContext} from "react-icons";
import { FaBeer } from 'react-icons/fa';
import './App.css'
class App extends component {
return (
<div>
<IconContext.Provider value={{ className="myReact-icons"}}>
<FaBeer />
</IconContext.Provider>
</div>);
}
App.css
.myreact-icons {
color: red;
height: 2em;
}
默认大小为 1em。您可以这样更改它:
import { FcSurvey } from 'react-icons/fc';
<FcSurvey size={'2em'} />
我有一位设计师给我的像素大小并不总是对应于 FontAwesome 的大小选项之一。所以我正在设置 CSS 高度。
<FontAwesomeIcon icon={faBars} style={{ height: "20px" }} />
React-Icons 有一个叫做 size 的属性,可以用来设置任何你想要的尺寸。 从 react-icon 库中导入 react-icon 后,您可以轻松地做这样的事情。
<FaUsers size={'4rem'} />