user1673498 user1673498 -4 years ago 95
CSS Question

Bootsrap Navbar Add <hr> before and after links

I have a bootsrap navbar, when a dropdown is expanded I would like to add a line break line under the dropdown and the last item in the list.

I have mad a Bootply and attached an image to illusrate what im trying to do.

enter image description here

Here is my Jquery.

$('.dropdown.open .dropdown-toggle').append('<hr class="break-sec-w">');

Answer Source

Your hr should be wrapped within a div to take effect.

I tried modifying your code-- Try the dropdowns

Example

 $(document).ready(function($) {   

$('.hr_line').append('<hr class="break-sec-w">');
  
  });
 .break-sec-w {
    width: 40px;
    
    border-top: 1px solid red;
    margin-top: 10px !important;
}
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
      
     
       </head>
       <body>
       
       <div class="container">

      <!-- Static navbar -->
      <nav class="navbar navbar-default">
        <div class="container-fluid">
          <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="#">Project name</a>
          </div>
          <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
              <li class="active"><a href="#">Home</a></li>
         
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown 2 <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                   <li><div class="hr_line"></div></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
              
             
                  <li><a href="#">Separated link</a></li>
                  <li><a href="#">One more separated link</a></li>
                   <li><div class="hr_line"></div></li>
                </ul>
              </li>
              
                       <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  
                  <li><a href="#">Action</a></li>
                  <li><div class="hr_line"></div></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
              
             
                  <li><a href="#">Separated link</a></li>
                  <li><a href="#">One more separated link</a></li>
                   <li><div class="hr_line"></div></li>
                </ul>
              </li>
                       <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown 3 <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">Action</a></li>
                   <li><div class="hr_line"></div></li>
                  <li><a href="#">Another action</a></li>
                  <li><a href="#">Something else here</a></li>
              
             
                  <li><a href="#">Separated link</a></li>
                  <li><a href="#">One more separated link</a></li>
                   <li><div class="hr_line"></div></li>
                </ul>
              </li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
              <li class="active"><a href="./">Default <span class="sr-only">(current)</span></a></li>
              <li><a href="../navbar-static-top/">Static top</a></li>
              <li><a href="../navbar-fixed-top/">Fixed top</a></li>
            </ul>
          </div><!--/.nav-collapse -->
        </div><!--/.container-fluid -->
      </nav>



    </div> <!-- /container -->
</body>
</html>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download