0

i am making a navigation bar and want to add a class to the main ULtag of the menu, does any one know how can i add class to to this element. Currently options and linkOptions are available which apply the attributes to the link / anchor and the parent LIof the anchor.

Here is my current code.

NavBar::begin([
        'innerContainerOptions'=>['class'=>'container-fluid'],
        'options' => [
            'class' => 'style-ihozflem','style'=>'left: 125px; width: 730px; position: absolute; top: 20px; height: 24px;','data'=>['state'=>'center notMobile', 'dropmode'=>"dropDown"]
        ],

    ]);
    echo Nav::widget([
        'encodeLabels'=>false,
        'activateItems'=>true,
        'items' => $menuItems,
    ]);
    NavBar::end();

1 Answer 1

1

Just add options class to Nav::widget

echo Nav::widget([
    'options' => ['class' => 'whatever-class navbar-nav navbar-right'],
    'encodeLabels'=>false,
    'activateItems'=>true,
    'items' => $menuItems,
]);

Hope that will be helpful!

Sign up to request clarification or add additional context in comments.

3 Comments

hmm you are right about using options, and it adds the class to the UL tag but it still appends the default nav class on the UL, any idea how to do that
you can't remove the default nav class because the purpose of the Nav widget is to render bootstrap nav which uses this class. so if you want to render only ul with links you have to do it yourself using Html::ul, see this lists example: yiiframework.com/doc-2.0/guide-helper-html.html#lists
yeah i have to override he css properties for nav class rather than removing it .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.