Bootstrap下拉菜单问题

时间:2019-11-29 18:44:39

标签: css bootstrap-4

我需要有关Bootstrap 4.4.1的帮助。我有两个连续的下拉链接+菜单,分别用不同的名称用aria标记。但是,第二个下拉菜单显示的是与上一个链接相关联的菜单,而不是它本身的菜单,即使映射正确。

代码是:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<a class="dropdown-toggle" 
href="#" title="Actions" 
role="button" 
id="dropdownActionMenu13"
data-toggle="dropdown" 
aria-haspopup="true" 
aria-expanded="false">actions</a>&nbsp;
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownActionMenu13">
<a class="dropdown-item small" href="scaffold-category/action/13/hello_world">Hello World</a>
</div>

<a class="dropdown-toggle" 
href="#" title="Related" 
role="button" 
id="dropdownActionGoTo13"
data-toggle="dropdown" 
aria-haspopup="true" 
aria-expanded="false">related</a>&nbsp;
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownActionGoTo13">
<a class="dropdown-item small" href="scaffold-category/by/category/13">Category list</a>
<a class="dropdown-item small" href="scaffold-post/by/category/13">Post list</a>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

请帮助:)

非常感谢。

1 个答案:

答案 0 :(得分:1)

这是一个部分解决方案,您应该使用引导导航类,它应该可以正常工作。您只需使用<div>或使用<ul><li>来创建导航,就可以将所有内容分开:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
        integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
        integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
        crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
    
     <div>
        <a class="dropdown-toggle" href="#" title="Actions" role="button" id="dropdownActionMenu13" data-toggle="dropdown"
            aria-haspopup="true" aria-expanded="false">actions</a>&nbsp;
        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownActionMenu13">
            <a class="dropdown-item small" href="scaffold-category/action/13/hello_world">Hello World</a>
        </div>
    </div>
    <div>
        <a class="dropdown-toggle" href="#" title="Related" role="button" id="dropdownActionGoTo14" data-toggle="dropdown"
            aria-haspopup="true" aria-expanded="false">related</a>&nbsp;
        <div class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownActionGoTo14">
            <a class="dropdown-item small" href="scaffold-category/by/category/13">Category list</a>
            <a class="dropdown-item small" href="scaffold-post/by/category/13">Post list</a>
        </div>
    </div>

您还可以在此处查看如何将Navbar完美放置:

https://getbootstrap.com/docs/4.4/components/navbar/