最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论