箭头不会出现在导航栏Bootstrap 4菜单和子菜单中

时间:2018-03-17 00:11:21

标签: css html5 css3 bootstrap-4 asp.net-core-2.0

我尝试使用带有嵌套子菜单的Twitter Bootstrap 4中的navbar组件,但是菜单项中包含子菜单的箭头根本没有出现,我不是没有原因。

此处出现箭头:

here arrow appear

但没有出现在我身边:

enter image description here 这是我的HTML代码的基本概要:

<div class="container-fluid">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">

            <a class="navbar-brand" asp-controller="Home" asp-action="Index">Right Way</a>

            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav m-auto justify-content-center">
                    <li class="nav-item active">
                        <a class="nav-link" asp-controller="Home" asp-action="Index">Home <span class="sr-only">(current)</span></a>
                    </li>

                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Dropdown
                        </a>
                        <ul class="dropdown-menu" id="sss" aria-labelledby="navbarDropdownMenuLink">
                            <li><a class="dropdown-item" href="#">Action</a></li>
                            <li><a class="dropdown-item" href="#">Another action</a></li>
                            <li class="dropdown-submenu">
                                <a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="#">Submenu</a></li>
                                    <li><a class="dropdown-item" href="#">Submenu0</a></li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Submenu 1</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                                            <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Submenu 2</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                                            <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>

                    </li>
                </ul>

            </div>
    </nav>
</div>

这是我的CSS代码:

.navbar-nav li:hover > ul.dropdown-menu {
    display: block;
}

.dropdown-submenu {
    position: relative;
}

.dropdown-submenu > .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -6px;
}

/* rotate caret on hover */
.dropdown-menu > li > a:hover:after {
    text-decoration: underline;
    transform: rotate(-90deg);
}

我不知道我怎么都做错了。

2 个答案:

答案 0 :(得分:0)

没有在Bootstrap中为子菜单上的箭头写入的方法。你必须自定义css才能这样做。

有一种方法可以在Drop项目上添加<span class="caret"></span>,但Bootstrap 4已将其替换为::after。查看此链接以获取更多信息https://getbootstrap.com/docs/4.0/migration/#dropdowns

所以想法是你必须通过获取项目是否有下拉列表来添加CSS。

但是我已经将你的代码添加为小提琴,它在这里工作正常。

.navbar-nav li:hover > ul.dropdown-menu {
    display: block;
}

.dropdown-submenu {
    position: relative;
}

.dropdown-submenu > .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -6px;
}

/* rotate caret on hover */
.dropdown-menu > li > a:hover:after {
    text-decoration: underline;
    transform: rotate(-90deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://getbootstrap.com/dist/js/bootstrap.min.js"></script>


<div class="container-fluid">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">

            <a class="navbar-brand" asp-controller="Home" asp-action="Index">Right Way</a>

            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav m-auto justify-content-center">
                    <li class="nav-item active">
                        <a class="nav-link" asp-controller="Home" asp-action="Index">Home <span class="sr-only">(current)</span></a>
                    </li>

                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            Dropdown
                        </a>
                        <ul class="dropdown-menu" id="sss" aria-labelledby="navbarDropdownMenuLink">
                            <li><a class="dropdown-item" href="#">Action</a></li>
                            <li><a class="dropdown-item" href="#">Another action</a></li>
                            <li class="dropdown-submenu">
                                <a class="dropdown-item dropdown-toggle" href="#">Submenu</a>
                                <ul class="dropdown-menu">
                                    <li><a class="dropdown-item" href="#">Submenu</a></li>
                                    <li><a class="dropdown-item" href="#">Submenu0</a></li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Submenu 1</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                                            <li><a class="dropdown-item" href="#">Subsubmenu1</a></li>
                                        </ul>
                                    </li>
                                    <li class="dropdown-submenu">
                                        <a class="dropdown-item dropdown-toggle" href="#">Submenu 2</a>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                                            <li><a class="dropdown-item" href="#">Subsubmenu2</a></li>
                                        </ul>
                                    </li>
                                </ul>
                            </li>
                        </ul>

                    </li>
                </ul>

            </div>
    </nav>
</div>

由于

答案 1 :(得分:0)

将以下内容添加到CSS

.dropdown-toggle::after {
  transform: rotate(-90deg);
  -webkit-transform: rotate(-90deg);
  right: 100px;
}