【问题标题】:Bootstrap nav pill in a table表中的引导导航药丸
【发布时间】:2019-12-23 23:10:13
【问题描述】:

我想在表格中使用 Bootstrap Nav Pills,并在最后一个表格的行中使用“选项卡按钮”。 选项卡内容在表格之外。我试过了,但它不起作用。

https://jsfiddle.net/wxkd6r2q/

    <table class="table">
  <caption>List of users</caption>
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First</th>
      <th scope="col">Last</th>
      <th scope="col">Handle</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th></th>
      <td> <a data-toggle="tab" href="#home">BUTTON HERE</a>    </td>
      <td> <a data-toggle="tab" href="#profile">BUTTON HERE</a> </td>
      <td> <a data-toggle="tab" href="#contact">BUTTON HERE</a> </td>
    </tr>
  </tbody>
</table>

<div class="tab-content" id="myTabContent">
  <div class="tab-pane fade show active" id="home" role="tabpanel">...home..</div>
  <div class="tab-pane fade" id="profile" role="tabpanel">...profile...</div>
  <div class="tab-pane fade" id="contact" role="tabpanel">...contact...</div>
</div>

【问题讨论】:

    标签: javascript css twitter-bootstrap bootstrap-4


    【解决方案1】:

    要让它工作:

    • nav-tabstab-content 类需要是兄弟姐妹才能使其工作...这是通过将表格放入带有 nav-tabs 的 div 中以使其工作
    • 另外,带有data-toggle="tab" 的DOM 元素必须是彼此的兄弟...所以我们将data-toggle="tab"&lt;td&gt; 内的&lt;a&gt; 移动到&lt;td&gt; 本身

    工作 sn-p 如下:

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
    
    <div class="nav nav-tabs">
    
      <table class="table">
        <caption>List of users</caption>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Handle</th>
          </tr>
        </thead>
        <tbody>
          <tr class="nav nav-tabs">
            <th>3</th>
            <td data-toggle="tab" href="#home"> <a>BUTTON HERE</a> </td>
            <td data-toggle="tab" href="#profile"> <a>BUTTON HERE</a> </td>
            <td data-toggle="tab" href="#contact"> <a>BUTTON HERE</a> </td>
          </tr>
        </tbody>
      </table>
    </div>
    
    <div class="tab-content" id="myTabContent">
      <div class="tab-pane fade active" id="home" role="tabpanel">...home..</div>
      <div class="tab-pane fade" id="profile" role="tabpanel">...profile...</div>
      <div class="tab-pane fade" id="contact" role="tabpanel">...contact...</div>
    </div>

    根据提问者对先前代码的观察进行更新...

    【讨论】:

    • 谢谢,但如果我单击#Home,然后单击#Profile,之后我将无法再单击#Home,因为它仍然处于激活状态。您可以在 sn-p 中看到相同的行为
    • 嗨@sparkle,我希望你有一个美好的圣诞节......我已经根据你很好的观察更新了答案,请检查
    • 谢谢。圣诞快乐。我刚刚为格式化添加了这个:
    猜你喜欢
    • 1970-01-01
    • 2018-09-12
    • 1970-01-01
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多