没有不值得去解决的问题,也没有不值得去学习的技术!

Adjust the Yii2 Starter Kit Backend Theme to Match the Design

Check the adjusted interface. The sidebar background color, top bar background color, and sidebar width (changed from 230px to 280px) have all been updated and are consistent with the design

1. Previous article: https://www.shuijingwanwq.com/2017/11/30/2084/

2. The current default interface is shown in Figure 1.

The current default interface
Figure 1

3. The designed UI interface needs to be implemented as shown in Figure 2.

The designed UI interface needs to be implemented
Figure 2

4. Copy \vendor\bower\admin-lte\build\less\variables.less to \backend\web\themes\default\css\variables.less, and clear all its contents.

5. Create \backend\web\themes\default\css\_all-skins.less, as shown in Figure 3.

Create: \backend\web\themes\default\css\_all-skins.less
Figure 3
LESS

@admin-lte-path: "../../../../../vendor/bower/admin-lte";
@import "@{admin-lte-path}/build/less/skins/_all-skins.less";
@import "variables.less";

6. Create \backend\web\themes\default\css\AdminLTE.less, as shown in Figure 4.

Create: \backend\web\themes\default\css\AdminLTE.less
Figure 4
LESS

@admin-lte-path: "../../../../../vendor/bower/admin-lte";
@import "@{admin-lte-path}/build/less/AdminLTE.less";
@import "variables.less";

7. Create \backend\assets\AdminLte.php, which inherits from \common\assets\AdminLte, and set $css to an empty array. Because we need to set Less variables and regenerate the corresponding CSS files, the default CSS files must be removed, as shown in Figure 5.

Create: \backend\assets\AdminLte.php, inherit from \common\assets\AdminLte, and set $css to an empty array. Because we need to set Less variables and regenerate the corresponding CSS files, the default CSS files must be removed
Figure 5
PHP

namespace backend\assets;

class AdminLte extends \common\assets\AdminLte
{
    public $css = [
    ];
}

8. Based on steps 5 and 6, the corresponding CSS files have been automatically compiled. Reference URL: https://www.shuijingwanwq.com/2017/12/07/2108/ , as shown in Figure 6.

Based on steps 5 and 6, the corresponding CSS files have been automatically compiled. Reference URL: https://www.shuijingwanwq.com/2017/12/07/2108/
Figure 6

9. Edit \backend\assets\BackendAsset.php to adjust the array of CSS files for this asset bundle, as shown in Figure 7.

Edit: \backend\assets\BackendAsset.php, adjust the array of CSS files for this asset bundle
Figure 7
PHP

    public $css = [
        'css/AdminLTE.css',
        'css/_all-skins.css',
        'css/style.css'
    ];

10. Analyze the sidebar background color, which is set in \vendor\bower\admin-lte\dist\css\skins\_all-skins.min.css, as shown in Figure 8.

Analyze the sidebar background color, which is set in \vendor\bower\admin-lte\dist\css\skins\_all-skins.min.css
Figure 8

11. Get the sidebar background color from the UI design, as shown in Figure 9.

Get the sidebar background color from the UI design
Figure 9

12. Search for #222d32 in \vendor\bower\admin-lte\build\less\variables.less, as shown in Figure 10.

Search for #222d32 in \vendor\bower\admin-lte\build\less\variables.less
Figure 10

13. Copy @sidebar-dark-bg: #222d32; to \backend\web\themes\default\css\variables.less, and change it to: @sidebar-dark-bg: #293e50;. Adjust the other variables similarly, as shown in Figure 11.

Copy @sidebar-dark-bg: #222d32; to \backend\web\themes\default\css\variables.less, and change it to: @sidebar-dark-bg: #293e50;. Adjust the other variables similarly
Figure 11

14. Check the adjusted interface. The sidebar background color, top bar background color, and sidebar width (changed from 230px to 280px) have all been updated and are consistent with the design, as shown in Figure 12.

Check the adjusted interface. The sidebar background color, top bar background color, and sidebar width (changed from 230px to 280px) have all been updated and are consistent with the design
Figure 12

15. View the source code. AdminLTE.css and _all-skins.css have now been themed, as shown in Figure 13.

View the source code. AdminLTE.css and _all-skins.css have now been themed
Figure 13

16. Besides recompiling everything into brand-new CSS files based on Less variables, there is another theming approach. This involves extracting the Less code that uses the Less variables needing adjustment, and compiling only the code that needs to be overridden. However, this approach requires analyzing the source code, making extraction somewhat difficult. Therefore, I recommend adopting the full recompilation approach.

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系