How to make a <button> in Bootstrap look like a normal link in nav-tabs?

后端 未结 6 886
春和景丽
春和景丽 2020-12-29 00:45

I\'m working in (formerly Twitter) Bootstrap 2 and I wanted to style buttons as though they were normal links. Not just any normal links, though; these are going in a

相关标签:
6条回答
  • 2020-12-29 01:10

    In bootstrap 3, this works well for me:

    .btn-link.btn-anchor {
        outline: none !important;
        padding: 0;
        border: 0;
        vertical-align: baseline;
    }
    

    Used like:

    <button type="button" class="btn-link btn-anchor">My Button</button>
    

    Demo

    0 讨论(0)
  • 2020-12-29 01:10

    I've tried all examples, posted here, but they do not work without extra CSS. Try this:

    <a href="http://www.google.com"><button type="button" class="btn btn-success">Google</button></a>
    

    Works perfectly without any extra CSS.

    0 讨论(0)
  • 2020-12-29 01:19

    Just make regular link look like button :)

    <a href="#" role="button" class="btn btn-success btn-large">Click here!</a>
    

    "role" inside a href code makes it look like button, ofc you can add more variables such as class.

    0 讨论(0)
  • 2020-12-29 01:20

    As noted in the official documentation, simply apply the class(es) btn btn-link:

    <!-- Deemphasize a button by making it look like a link while maintaining button behavior -->
    <button type="button" class="btn btn-link">Link</button>
    

    For example, with the code you have provided:

    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />
    
    
    <form action="..." method="post">
      <div class="row-fluid">
        <!-- Navigation for the form -->
        <div class="span3">
          <ul class="nav nav-tabs nav-stacked">
            <li>
              <button class="btn btn-link" role="link" type="submit" name="op" value="Link 1">Link 1</button>
            </li>
            <li>
              <button class="btn btn-link" role="link" type="submit" name="op" value="Link 2">Link 2</button>
            </li>
            <!-- ... -->
          </ul>
        </div>
        <!-- The actual form -->
        <div class="span9">
          <!-- ... -->
        </div>
      </div>
    </form>

    0 讨论(0)
  • 2020-12-29 01:20

    Just add remove_button_css as class to your button tag. You can verify the code for Link 1

    .remove_button_css { 
      outline: none;
      padding: 5px; 
      border: 0px; 
      box-sizing: none; 
      background-color: transparent; 
    }
    

    enter image description here

    Extra Styles Edit

    Add color: #337ab7; and :hover and :focus to match OOTB (bootstrap3)

    .remove_button_css:focus,
    .remove_button_css:hover {
        color: #23527c;
        text-decoration: underline;
    }
    
    0 讨论(0)
  • 2020-12-29 01:20

    Just get rid of the background color, borders and add hover effects. Here's a fiddle: http://jsfiddle.net/yPU29/

    <form action="..." method="post">
    <div class="row-fluid">
    <!-- Navigation for the form -->
    <div class="span3">
      <ul class="nav nav-tabs nav-stacked">
        <li><button type="submit" name="op" value="Link 1" class="button-link">Link 1</button></li>
        <li><button type="submit" name="op" value="Link 2" class="button-link">Link 2</button></li>
        <!-- ... -->
      </ul>
    </div>
    <!-- The actual form -->
    <div class="span9">
      <!-- ... -->
    </div>
    </div>
    </form>
    

    CSS:

    .button-link {
    background-color: transparent;
    border: none;
    }
    
    .button-link:hover {
    color: blue;
    text-decoration: underline;
    }
    
    0 讨论(0)
提交回复
热议问题