Navbar - Need to Extend top and bottom line to 100%

Viewed 45

I am trying to extend the lines full width of a navbar instead of just covering the links. I think the code/stylesheet on line 7(include) is interfering with the html style tags below Lines 12-21. However if I remove this line then the background which is dark disappears and the links are displayed as a list instead.

<!doctype html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
 <style>

.navbar-nav a {

  border-top:3px solid #DB9842;
  border-bottom: 3px solid #DB9842;
  
}

</style> 
<body>
<div>
  <nav class="navbar-nav navbar-expand-sm bg-dark">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#">Link 1</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 2</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 3</a>
      </li>
    </ul>
  </nav>
</div>
</body>
</html>

2 Answers

Remove A From Your Style Address

You had a border on the a link rather than the .navbar-nav. The a link style will only cover the clickable part, not the whole navigation area.

To solve this, if you remove the a from the style, as per the below code, it will span the entire width of the navigation.

.navbar-nav {
  border-top:3px solid #DB9842;
  border-bottom: 3px solid #DB9842;
}

Because the .navbar-nav style is on also on the ul element it was creating double borders. To prevent this I added the below code so that the border is only applied to the navigation area and not the ul.

.navbar-nav ul {border:none;}

enter image description here

<!doctype html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
 <style>

.navbar-nav {
  border-top:3px solid #DB9842;
  border-bottom: 3px solid #DB9842;
}
.navbar-nav ul {border:none;}
</style> 
<body>
<div>
  <nav class="navbar-nav navbar-expand-sm bg-dark">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#">Link 1</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 2</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 3</a>
      </li>
    </ul>
  </nav>
</div>
</body>
</html>

Hope this may help you.

<!doctype html>
<html>
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
 <style>

.border_color{

  border-top:3px solid #DB9842;
  border-bottom: 3px solid #DB9842;
  
}

</style> 
<body>
<div class="border_color">
  <nav class="navbar-nav navbar-expand-sm bg-dark">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="#">Link 1</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 2</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Link 3</a>
      </li>
    </ul>
  </nav>
</div>
</body>
</html>

Related