yii2 navbar with dropdown

前端 未结 2 1795
猫巷女王i
猫巷女王i 2021-02-05 09:55

After some simple edit on the default navbar, I got the code for the menu below... It would be very ugly if I add more menus.



        
相关标签:
2条回答
  • 2021-02-05 10:07

    From the official documentation. I got the answer. I changed the options from nav-pills to navbar-nav

    echo Nav::widget([
        'items' => [
            [
                'label' => 'Home',
                'url' => ['site/index'],
                'linkOptions' => [...],
            ],
            [
                'label' => 'Dropdown',
                'items' => [
                     ['label' => 'Level 1 - Dropdown A', 'url' => '#'],
                     '<li class="divider"></li>',
                     '<li class="dropdown-header">Dropdown Header</li>',
                     ['label' => 'Level 1 - Dropdown B', 'url' => '#'],
                ],
            ],
        ],
        'options' => ['class' =>'navbar-nav'],
    ]);
    
    0 讨论(0)
  • 2021-02-05 10:30

    Well I don't have the reputation needed but, just to be more correct on the "nerison" answer, add the nav class too: like these

    'options' => ['class' =>'nav navbar-nav'],
    
    0 讨论(0)
提交回复
热议问题