在 PHP 项目中优雅的使用 Font-Awesome
Font-Awesome是一套非常流行的图标库,包含了大量精美图标资源,在全球范围内都有大量的使用者。
Easy FontAwesome是个简单的小工具,可以帮助你在PHP项目中优雅的使用Font-Awesome
。
安装
composer require encore/easy-fa
使用
要在Laravel
中使用,先添加service provider
到app.php
:
Encore\EasyFontAwesome\FontAwesomeServiceProvider::class,
然后在视图中使用:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>FontAwesome example</title>
<!-- 引入css -->
{!! fa_assets() !!}
</head>
<body>
<botton>{!! fa('star') !!}</botton>
<botton>{!! fa('calendar')->lg() !!}</botton>
<botton>{!! fa('camera')->lg()->border() !!}</botton>
<botton>{!! fa('flag')->x2()->rotate(180) !!}</botton>
<!-- or -->
<botton>@fa('star')</botton>
<botton>@fa('calendar', 'lg')</botton>
<botton>@fa('camera', 'lg|border')</botton>
<botton>@fa('hourglass', 'x2|rotate:180')</botton>
</body>
</html>
除了laravel
外,可以在任何PHP项目中使用它
echo fa('star')
// size
echo fa('star')->lg();
echo fa('star')->x2();
echo fa('star')->x3();
echo fa('star')->x4();
echo fa('star')->x5();
// fixed with parent
echo fa('star')->fw();
// add border
echo fa('star')->border();
// add border and pull left
echo fa('star')->border()->left();
// add border and pull right
echo fa('star')->border()->right();
// spin
echo fa('star')->spin();
// pulse
echo fa('star')->spin()->pulse();
// rotate
echo fa('star')->rotate(90);
echo fa('star')->rotate(180);
echo fa('star')->rotate(270);
// flip
echo fa('star')->flipHorizontal();
echo fa('star')->flipVertical();
// stack
echo fa('star')->on(fa('square'));
// inverse
echo fa('star')->inverse();
// iterat
foreach (fa(['book', 'pencil', 'star', 'gear']) as $fa) {
echo $fa;
}
显示效果请参考 http://fontawesome.io/examples/
有需要使用Font-Awesome
的同学不妨试试这个工具。
本帖已被设为精华帖!
本帖由系统于 4年前 自动加精