Bootstrap 3.0 Button in Navbar

后端 未结 5 1414
春和景丽
春和景丽 2021-01-30 07:57

I upgraded bootstrap 3.0 now. And \"a\" tag which looks like btn (by the help of class .btn) is ruined on navbar.

  • 相关标签:
    5条回答
    • 2021-01-30 08:30

      Wrap a <p class="navbar-btn"> around the <a class="btn">:

      <nav class="navbar navbar-default navbar-fixed-top">
          <div class="container">
              <ul class="nav navbar-nav">
                  <li>
                      <p class="navbar-btn">
                          <a href="#" class="btn btn-default">I'm a link button!</a>
                      </p>
                  </li>
              </ul>
          </div>
      </nav>
      

      JSFiddle: http://jsfiddle.net/lachlan/398kj/

      Screenshot:
      Bootstrap link button in navbar

      0 讨论(0)
    • 2021-01-30 08:31

      The problem is that the selector for styling an anchor in a navbar is: .nav > li > a which means it has a higher precedence than a .navbar-btn.

      You can fix by just wrapping it in another tag like a span. I don't think you should use a form tag as others suggest as it's not a form at all.

      0 讨论(0)
    • 2021-01-30 08:35

      http://learnangular2.com/events/

      EVENT OBJECT

      To capture the event object, pass $event as a parameter in the event callback from the template:

      <button (click)="clicked($event)"></button>
      

      This is an easy way to modify the event, such as calling preventDefault:

      @Component(...)
      class MyComponent {
        clicked(event) {
          event.preventDefault();
        }
      }
      
      0 讨论(0)
    • 2021-01-30 08:48

      Now, bootstrap 3 has buttons in the navbar like this:

      <button type="button" class="btn btn-default navbar-btn">Sign in</button>

      It uses navbar-btn so it knows it's in the navbar.

      If you want it to work, do this:

      <li>
          <form action="#">
              <button class="btn btn-default navbar-btn">Link</button>
          </form>
      </li>
      

      This way, it still acts like an anchor tag. Just change # for the value you actually want it to go to.

      So for this instance:

      <li>
          <form action="<?php echo BASE_PATH; ?>register.php">
              <button class="btn btn-default navbar-btn">Link</button>
          </form>
      </li>
      
      0 讨论(0)
    • 2021-01-30 08:56

      With bootstrap 3, it is still possible to have a <a>link rendered as a button, but you have to include them into a <form>. Also, the <a> should include the navbar-btn class.

      <li>
        <form>
          <a href="#" class="btn btn-primary btn-sm navbar-btn">
            register
          </a>
        </form>
      </li>
      
      0 讨论(0)
    提交回复
    热议问题