如何使Bootstrap中的<button>看起来像nav-tabs中的普通链接?</button>

时间:2013-11-14 15:41:55

标签: html css twitter-bootstrap

我正在(原Twitter)Bootstrap 2工作,我想把按钮设置为普通链接。不过,不只是任何正常的链接;这些都在<ul class="nav nav-tabs nav-stacked">容器中。标记最终将如下所示:

<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">Link 1</button></li>
        <li><button type="submit" name="op" value="Link 2">Link 2</button></li>
        <!-- ... -->
      </ul>
    </div>
    <!-- The actual form -->
    <div class="span9">
      <!-- ... -->
    </div>
  </div>
</form>

Bootstrap是否有办法让这些<button>看起来像<a>个?{/ p>

7 个答案:

答案 0 :(得分:171)

As noted in the official documentation,只需应用类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>

例如,使用您提供的代码:

&#13;
&#13;
<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>
&#13;
&#13;
&#13;

答案 1 :(得分:27)

只需使常规链接看起来像按钮:)

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

&#34;作用&#34;在href代码中使它看起来像按钮,ofc你可以添加更多的变量,比如class。

答案 2 :(得分:10)

只需将remove_button_css作为类添加到按钮标记即可。您可以验证链接1的代码

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

enter image description here

额外样式编辑

添加color: #337ab7;:hover以及:focus以匹配OOTB(bootstrap3)

.remove_button_css:focus,
.remove_button_css:hover {
    color: #23527c;
    text-decoration: underline;
}

答案 3 :(得分:2)

只需摆脱背景颜色,边框并添加悬停效果。这是一个小提琴: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;
}

答案 4 :(得分:2)

在引导程序3中,这对我来说效果很好:

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

使用方式:

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

Demo

答案 5 :(得分:1)

我已经尝试了所有在此发布的示例,但如果没有额外的CSS,它们就无法运行。试试这个:

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

完美无需任何额外的CSS。

答案 6 :(得分:0)

这是一个例子,为了将字体真棒图标显示为普通链接,我相信通过向按钮标签添加“linkish”类,它会和你一起工作,这是我的例子:

<form method="POST" > 
  <button type="submit" class="linkish  my-1 far fa-thumbs-down fa-2x">  </button>
</form>

和css样式:

.linkish {
    background-color: transparent!important;
    border: 0!important;
    color: blue!important;
    cursor: pointer!important;
    display: inline!important;
    margin: 0!important;
    outline: none!important;
    padding: 0!important;
    text-decoration: none!important;
}



.linkish:hover {
 text-decoration: underline!important;
}