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

时间:2014-09-14 10:07:58

标签: yii2

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

示例:

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

这不起作用

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

1 个答案:

答案 0 :(得分:23)

只需打开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.
     **/

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

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

如果您想要添加类链接

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