下拉菜单不显示 Bootstrap
Dropdown menu doesn't show Bootstrap
我一直在尝试在我的页面上显示下拉菜单,但它不起作用...
我的HTML代码:
<div class="dropdown d-inline">
<div class="widget-header mr-3">
<button href="#" class="icon icon-sm rounded-circle border" data-toggle="dropdown"><i class="fa fa-shopping-cart"></i></button>
<span class="badge badge-pill badge-danger notify">{{ Cart::count() }}</span>
</div>
<div class="dropdown-menu p-3 dropdown-menu-right" style="min-width:280px;">
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/1.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Name of item nice iteme</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/2.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Some other item name is here</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/3.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Another name of item item</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<div class="price-wrap text-center py-3 border-top">
Subtotal: <strong class="h5 price">00</strong>
</div>
<a href="" class="btn btn-primary btn-block"> Checkout </a>
</div> <!-- drowpdown-menu.// -->
</div>
我的 Bootsrap 集成:
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
这是 Laravel 上的 .blade.php 页 运行。
提前谢谢你的帮助,我真的卡住了。
尝试添加一个 id="test" 到按钮标签和下拉菜单 div 一个名为 aria-labelledby="test".
的属性
所以看来是在 .dropdown .d-inline
之后将 <button>
包裹在 div
中导致了您的问题。 Here 也是一个可用的 CodePen(请注意,我为每个 Bootstrap 添加了一些属性到某些元素)。
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>
<div class="dropdown d-inline">
<button type="button" class="icon icon-sm rounded-circle border dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
hello
</button>
<span class="badge badge-pill badge-danger notify">{{ Cart::count() }}</span>
<div class="dropdown-menu p-3 dropdown-menu-right">
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/1.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Name of item nice iteme</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/2.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Some other item name is here</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/3.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Another name of item item</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<div class="price-wrap text-center py-3 border-top">
Subtotal: <strong class="h5 price">00</strong>
</div>
<a href="" class="btn btn-primary btn-block"> Checkout </a>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
我一直在尝试在我的页面上显示下拉菜单,但它不起作用...
我的HTML代码:
<div class="dropdown d-inline">
<div class="widget-header mr-3">
<button href="#" class="icon icon-sm rounded-circle border" data-toggle="dropdown"><i class="fa fa-shopping-cart"></i></button>
<span class="badge badge-pill badge-danger notify">{{ Cart::count() }}</span>
</div>
<div class="dropdown-menu p-3 dropdown-menu-right" style="min-width:280px;">
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/1.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Name of item nice iteme</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/2.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Some other item name is here</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/3.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Another name of item item</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<div class="price-wrap text-center py-3 border-top">
Subtotal: <strong class="h5 price">00</strong>
</div>
<a href="" class="btn btn-primary btn-block"> Checkout </a>
</div> <!-- drowpdown-menu.// -->
</div>
我的 Bootsrap 集成:
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
这是 Laravel 上的 .blade.php 页 运行。 提前谢谢你的帮助,我真的卡住了。
尝试添加一个 id="test" 到按钮标签和下拉菜单 div 一个名为 aria-labelledby="test".
的属性所以看来是在 .dropdown .d-inline
之后将 <button>
包裹在 div
中导致了您的问题。 Here 也是一个可用的 CodePen(请注意,我为每个 Bootstrap 添加了一些属性到某些元素)。
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
</head>
<body>
<div class="dropdown d-inline">
<button type="button" class="icon icon-sm rounded-circle border dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
hello
</button>
<span class="badge badge-pill badge-danger notify">{{ Cart::count() }}</span>
<div class="dropdown-menu p-3 dropdown-menu-right">
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/1.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Name of item nice iteme</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/2.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Some other item name is here</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<figure class="itemside mb-3">
<div class="aside">
<img src="bootstrap-ecommerce-html/images/items/3.jpg" class="img-sm border">
</div>
<figcaption class="info align-self-center">
<p class="title">Another name of item item</p>
<a href="#" class="float-right"><i class="fa fa-trash"></i></a>
<div class="price">0</div> <!-- price-wrap.// -->
</figcaption>
</figure>
<div class="price-wrap text-center py-3 border-top">
Subtotal: <strong class="h5 price">00</strong>
</div>
<a href="" class="btn btn-primary btn-block"> Checkout </a>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>