100%宽度水平下拉菜单中的Bootstrap水平100%宽度下拉菜单?

时间:2017-04-13 09:19:57

标签: html css twitter-bootstrap drop-down-menu

大家好日子,

我正在尝试制作来自“Menu2”的100%宽度水平下拉菜单。在“Menu2” - >“SubMenu2”Iam尝试制作100%宽度水平下拉菜单SubSubMenu。有关最佳解决方案的任何想法吗?

非常感谢所有人的帮助。

body {
  min-height: 2000px;
  padding-top: 70px;
}


.navbar .navbar-nav {
    display: inline-block;
    float: none;
}

.navbar .navbar-collapse {
    text-align: center;
}

.dropdown-submenu{position:relative;}

.dropdown-submenu>.dropdown-menu{top:0;left:100%;margin-top:-6px;margin-left:-1px;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;}

.dropdown-submenu:hover>.dropdown-menu{display:block;}

.dropdown-submenu>a:after{display:block;content:" ";float:right;width:0;height:0;border-color:transparent;border-style:solid;border-width:5px 0 5px 5px;border-left-color:#cccccc;margin-top:5px;margin-right:-10px;}

.dropdown-submenu:hover>a:after{border-left-color:#ffffff;}

.dropdown-submenu.pull-left{float:none;}.dropdown-submenu.pull-left>.dropdown-menu{left:-100%;margin-left:10px;-webkit-border-radius:6px 0 6px 6px;-moz-border-radius:6px 0 6px 6px;border-radius:6px 0 6px 6px;}


@import url('http://getbootstrap.com/dist/css/bootstrap.css');
.dropdown > li{
  display: inline-block;
    float:center;
    
 }
.open> ul {
    display: inline-flex !important;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Test</title>

    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="style.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <!-- Fixed navbar -->
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Logo</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li><a href="#about">Menu1</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Menu2</a>
              <ul class="dropdown-menu">
                <li><a href="#">SubMenu1</a></li>
                <li class="dropdown-submenu"><a href="#">SubMenu2</a>
                   <ul class="dropdown-menu">
                        <li><a href="#">SubSubMenu1</a></li>
                        <li><a href="#">SubSubMenu2</a></li>
                        <li><a href="#">SubSubMenu3</a></li>
                   </ul>
                  </li>          
                <li><a href="#">SubMenu3</a></li>
            </ul>
            </li>
              <li><a href="#contact">Menu3</a></li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li><a href="../navbar/">ENG</a></li>
              <li><a href="../navbar/">LT</a></li>
              </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>
      

     

    <div class="container">

      <!-- Main component for a primary marketing message or call to action -->
      <div class="jumbotron">
        <h1></h1>
        <p></p>
        <p></p>
        <p>
          <a class="btn btn-lg btn-primary" href="#" role="button">Button</a>
        </p>
      </div>

    </div> <!-- /container -->


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>
    <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

重点是禁用下拉列表position: relative并将其放在具有所需宽度的父级上:

#navbar {
  position: relative;
}
#navbar .dropdown.has-container {
  position: static;
}
#navbar .dropdown.has-container .dropdown-menu.container {
  margin: 0 -15px;
}
<!-- ... -->
  <li class="dropdown has-container">
     <a href="#" class="dropdown-toggle" 
        data-toggle="dropdown" role="button" 
        aria-haspopup="true" aria-expanded="false">Menu2</a>
     <ul class="dropdown-menu container">
        <li><a href="#">SubMenu1</a></li>
        <li class="dropdown-submenu"><a href="#">SubMenu2</a>
<!-- ... -->

概念证明: jsFiddle