Yii2如何在菜单项的标签中添加类

kou*_*wen 6 yii2

如何在Label(item)上添加CSS类

例:

['label'=>'Home', 'url'=>['site/home']]

这不起作用

['label'=>'Home', 'class'=>'list-group-item', 'url'=>['site/index']],

use*_*788 24

只需打开Nav小部件:

/**
     * @var array list of items in the nav widget. Each array element represents a single
     * menu item which can be either a string or an array with the following structure:
     *
     * - label: string, required, the nav item label.
     * - url: optional, the item's URL. Defaults to "#".
     * - visible: boolean, optional, whether this menu item is visible. Defaults to true.
     * - linkOptions: array, optional, the HTML attributes of the item's link.
     * - options: array, optional, the HTML attributes of the item container (LI).
     * - active: boolean, optional, whether the item should be on active state or not.
     * - items: array|string, optional, the configuration array for creating a [[Dropdown]] widget,
     *   or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
     **/
Run Code Online (Sandbox Code Playgroud)

因此,如果要将类添加到li项目,请使用

['label'=>'Home', 'url'=>['site/index'],'options'=>['class'=>'list-group-item']]
Run Code Online (Sandbox Code Playgroud)

如果你想添加类链接

[
  'label'=>'Home', 
  'url'=>['site/index'],
  'options'=> ['class'=>'list-group-item'],
  'linkOptions'=>['class'=>'item-a-class'],
]
Run Code Online (Sandbox Code Playgroud)