在 PHP 项目中优雅的使用 Font-Awesome

Font-Awesome是一套非常流行的图标库,包含了大量精美图标资源,在全球范围内都有大量的使用者。

Easy FontAwesome是个简单的小工具,可以帮助你在PHP项目中优雅的使用Font-Awesome

安装

composer require encore/easy-fa

使用

要在Laravel中使用,先添加service providerapp.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的同学不妨试试这个工具。

本帖已被设为精华帖!
本帖由系统于 3年前 自动加精
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!