How can I place a checkbox next to Bootstrap tab text and align all in the tab? - Stack Overflow

Could someone help me align the text and checkbox so they are both inside the Tabs here please, prefera

Could someone help me align the text and checkbox so they are both inside the Tabs here please, preferably without CSS or using inline CSS.

Ive tried a few diffent approaches, but bootstrap isn't my strong suit, im using a CRUD framework that handles the bootstrap side of things, but I need to do somthing like this so the end user can select tabs to export.

<div class="container">
  <ul class="nav nav-tabs">
  
    <!-- Tab 1 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Badger
          <input class="form-check-input" type="checkbox" id="checkTab1">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Cat
          <input class="form-check-input" type="checkbox" id="checkTab2">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Foo
          <input class="form-check-input" type="checkbox" id="checkTab3">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Bar
          <input class="form-check-input" type="checkbox" id="checkTab4">
        </span>
      </a>
    </li>
  </ul>
</div>

Fiddle here

Could someone help me align the text and checkbox so they are both inside the Tabs here please, preferably without CSS or using inline CSS.

Ive tried a few diffent approaches, but bootstrap isn't my strong suit, im using a CRUD framework that handles the bootstrap side of things, but I need to do somthing like this so the end user can select tabs to export.

<div class="container">
  <ul class="nav nav-tabs">
  
    <!-- Tab 1 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Badger
          <input class="form-check-input" type="checkbox" id="checkTab1">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Cat
          <input class="form-check-input" type="checkbox" id="checkTab2">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Foo
          <input class="form-check-input" type="checkbox" id="checkTab3">
        </span>
      </a>
    </li>
    
    <!-- Tab 2 with Checkbox -->
    <li class="nav-item">
      <a class="nav-link" href="#">
        <span class="d-flex align-items-center">
          Bar
          <input class="form-check-input" type="checkbox" id="checkTab4">
        </span>
      </a>
    </li>
  </ul>
</div>

Fiddle here

Share Improve this question edited Nov 20, 2024 at 16:39 isherwood 61.1k16 gold badges121 silver badges169 bronze badges asked Nov 20, 2024 at 15:36 MonkeyHunterMonkeyHunter 1
Add a comment  | 

1 Answer 1

Reset to default 0

in your case can use d-flex and align-items-center classes or use custom css, bootstrap tab borders and padding interfere with the checkbox placement

<div class="container">
 <ul class="nav nav-tabs">
<li class="nav-item">
  <a class="nav-link d-flex align-items-center" href="#">
    <span>Badger</span>
    <input class="form-check-input ms-auto" type="checkbox" id="checkTab1">
  </a>
</li>
<li class="nav-item">
  <a class="nav-link d-flex align-items-center" href="#">
    <span>Cat</span>
    <input class="form-check-input ms-auto" type="checkbox" id="checkTab2">
  </a>
</li>
<li class="nav-item">
  <a class="nav-link d-flex align-items-center" href="#">
    <span>Foo</span>
    <input class="form-check-input ms-auto" type="checkbox" id="checkTab3">
  </a>
</li>
<li class="nav-item">
  <a class="nav-link d-flex align-items-center" href="#">
    <span>Bar</span>
    <input class="form-check-input ms-auto" type="checkbox" id="checkTab4">
  </a>
</li>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742348145a4426966.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信