css - Q : Import Uikit in yii\bootstrap\NavBar

标签 css yii2 uikit navbar

我使用 Yii2 框架,我在 layout/main.php 中编写了一个导航栏。我必须使用 Uikit,所以我在我的元素中导入了 css 和 js 文件,现在的问题是 yii\bootstrap\NavBar 似乎不可定制并且不支持 uikit 类。有没有办法在 yii 导航栏中使用 uk 类和 span 标签?

我有这个 HTML 代码:

<nav class="uk-navbar-container" uk-navbar>
<div class="uk-navbar-left">
    <ul class="uk-navbar-nav">
        <li class="uk-active"><a href="#">Active</a></li>
        <li>
            <a href="#">Parent</a>
            <div class="uk-navbar-dropdown">
                <ul class="uk-nav uk-navbar-dropdown-nav">
                    <li class="uk-active"><a href="#">Active</a></li>
                    <li><a href="#">Item
                    <span class="uk-icon uk-margin-small-right" uk-icon="icon: star"></span>
                    </a></li>
                    <li class="uk-nav-header">Header</li>
                    <li><a href="#">Item</a></li>
                    <li><a href="#">Item</a></li>
                    <li class="uk-nav-divider"></li>
                    <li><a href="#">Item</a></li>
                </ul>
            </div>
        </li>
        <li><a href="#">Item</a></li>
    </ul>
</div>

<div class="uk-navbar-right">
    <ul class="uk-navbar-nav">
        <li>
            <a href="#">Parent</a>
            <div class="uk-navbar-dropdown">
                <ul class="uk-nav uk-navbar-dropdown-nav">
                    <li class="uk-active"><a href="#">Active</a></li>
                    <li><a href="#">Item</a></li>
                    <li class="uk-nav-header">Header</li>
                    <li><a href="#">Item</a></li>
                    <li><a href="#">Item</a></li>
                    <li class="uk-nav-divider"></li>
                    <li><a href="#">Item</a></li>
                </ul>
            </div>
        </li>
    </ul>
</div>

这是 yii2 组件的实现:

NavBar::begin([
'brandLabel' => Html::img('/img/my_image.png'),
'brandUrl' => Yii::$app->homeUrl,
'options' => [
    'class' => 'uk-navbar navbar-fixed-top uk-align-center',
    'style' => 'background-color: orange; color: black ; height: 100px; 
    margin-top: 0; margin-bottom: 0',
    ]
 ]);
$menuItems = [
['label' => 'Home', 'url' => Yii::$app->homeUrl],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
['label' => 'Item', 'url' => ['/item']],
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right uk-link-reset',
              'style' => 'color: white'
             ],
'items' => $menuItems,
]);
NavBar::end();

最佳答案

您需要在每个单独的元素中包含 html 选项

$menuItems = [
    ['label' => 'Home', 'url' => Yii::$app->homeUrl],
    [
        'label'   => 'Item <span class="uk-icon uk-margin-small-right" uk-icon="icon: star"></span>',
        'encode'  => false,
        'url'     => ['/item'],
        'options' => ['class' => 'uk-active'],
    ],
    ['label' => 'Item', 'url' => ['/item']],
    ['label' => 'Item', 'url' => ['/item']],
    ['label' => 'Item', 'url' => ['/item']]
];

元素的更多详细信息documentation :

  • 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.
  • dropDownOptions: array, optional, the HTML options that will passed to the yii\bootstrap\Dropdown widget.
  • items: array|string, optional, the configuration array for creating a yii\bootstrap\Dropdown widget, or a string representing the dropdown menu. Note that Bootstrap does not support sub-dropdown menus.
  • encode: boolean, optional, whether the label will be HTML-encoded. If set, supersedes the $encodeLabels option for only this item.

关于css - Q : Import Uikit in yii\bootstrap\NavBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53597344/

相关文章:

css - 如何解决弹出覆盖问题

php - yii2、谷歌 oauth2 和范围

objective-c - 为什么在更改 anchor 后设置框架时我的 View 会移动?

ios - 具有 Storyboard Segues 的上下文菜单预览提供程序

ios - 自定义编辑菜单中 UIMenuItems 的顺序

html - CSS 内联 block 不起作用?

html - CSS 三列,中间列固定宽度

javascript - 仅在 Chrome 中调整 Iframe 大小问题

javascript - 为什么 AJAX 重定向到 PHP 中的新页面

php - Yii2:编写表单 Action 的正确方式