Bootstrap菜单下拉列表未显示加载时的下拉箭头

时间:2017-12-29 23:42:34

标签: html css twitter-bootstrap

我正在尝试获取折叠菜单项以在页面加载时显示箭头,有没有办法执行此操作?目前正在加载时,在用户单击“文件”

之前,它不会显示箭头

这是我的代码:

<ul class="list-unstyled components">
            <p><b>Main Menu</b> </p>
            <li>
                <a href="#">About</a>
                <a href="#pageSubmenu" data-toggle="collapse">Files</a>
                <ul class="collapse list-unstyled " id="pageSubmenu">
                    <li><a href="#">+Photos</a></li>
                    <li><a href="#">+Videos</a></li>
                    <li><a href="#">+Music</a></li>
                </ul>
            </li>  
        </ul>

以下是正在发生的事情的截图

This is on page load
This is after I click on "files"
Finally this is after I close the list

正如您所见,加载页面时,右侧的箭头不会出现。试图让它出现让用户知道它是一个下拉列表

谢谢!

3 个答案:

答案 0 :(得分:0)

添加aria-expanded =&#34; false&#34;到

<a href="#pageSubmenu" data-toggle="collapse">Files</a>

所以它将是

<a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false">Files</a>

这将保持您当前的CSS

答案 1 :(得分:0)

&#13;
&#13;
$(document).ready(function(){
  $('.dropdown-submenu a.test').on("click", function(e){
    $(this).next('ul').toggle();
    e.stopPropagation();
    e.preventDefault();
  });
});
&#13;
<style>
.dropdown-menu{
border-radius:0px !important;
}
.dropdown-submenu {
    position: relative;
    border-radius:0px !important;
}
.dropdown-submenu .dropdown-menu {
    top: 0;
    left: 100%;
    margin-top: -1px;
    border-radius:0px !important;
}
</style>
&#13;
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>
<body>
   
<div class="container">
                                   
  <div class="dropdown">
    <button class="btn btn-success dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Menu Tutorials <span class="caret"></span></button>
    <ul class="dropdown-menu">
      <li><a tabindex="-1" href="#">Dropdown Menu 1</a></li>
      <li><a tabindex="-1" href="#">Dropdown Menu 2</a></li>
      <li class="dropdown-submenu">
        <a class="test" tabindex="-1" href="#">Dropdown Menu 3 <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="#">dropdown 1</a></li>
          <li><a tabindex="-1" href="#">dropdown 2</a></li>
          <li class="dropdown-submenu">
            <a class="test" href="#">dropdown 3 <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">dropdown 1</a></li>
              <li><a href="#">dropdown 2</a></li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </div>
</div>


</body>
</html>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

你有两个选择:

首先,将 aria-expanded="false" 添加到“a”标签中,如下所示:

<a href="#pageSubmenu" data-toggle="collapse" aria-expanded="false">Files</a>

第二,通过在“a”标签中使用“fontawesome”图标,如下所示:

<a href="#pageSubmenu" data-toggle="collapse" >Files <i class="fas fa-angle-down"></i> </a>

*如果您想使用“fontawesome”,请不要忘记在标题中安装“fontawesome”库,请参阅以下链接中的文档以获取更多信息:

https://fontawesome.com/v5.15/how-to-use/customizing-wordpress/snippets/setup-cdn-webfont#load-all-styles

我希望这有帮助。