使用 bootstrap 对齐容器内的步进器 div

A_K*_*A_K 5 html bootstrap-5

我在容器内的步进器中有一个标题图标列表,我试图让它们响应页面大小的变化,但它不起作用。我尝试更改容器在不同 div 中的位置,但没有成功。

我正在使用 Bootstrap5

这是当前的输出: 在此输入图像描述

我试图获取容器内的数字,这里是模板:

    <div class="container flex-grow-1 flex-shrink-0 py-5">
      <div class="mb-5 p-4 bg-white shadow-sm">
        <h1 class="text-center">Plan</h1>
        <div id="stepper1" class="bs-stepper">
          <div class="bs-stepper-header" role="tablist">
            <!-- General Information -->
            <div class="step active" data-target="#test-l-1">
              <button
                type="button"
                class="step-trigger"
                role="tab"
                id="stepper1trigger1"
                aria-controls="test-l-1"
                aria-selected="true"
              >
                <span class="bs-stepper-circle">1</span>
<!--                <span class="bs-stepper-label">General Information</span>-->
              </button>
            </div>
            <!-- Summary -->
            <div class="step" data-target="#test-l-2">
              <button
                type="button"
                class="step-trigger"
                role="tab"
                id="stepper1trigger2"
                aria-controls="test-l-2"
                aria-selected="false"
                
              >
                <span class="bs-stepper-circle">2</span>
<!--                <span class="bs-stepper-label">Summary</span>-->
              </button>
            </div>
        </div>
      </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

小智 4

对于每个 ,您可以在和类中使用col类。它会根据屏幕的宽度自动调整每个按钮的宽度。使用类时,每个都会占据相等的空间。在我们的例子中,有 10 个元素,每个元素占据整个宽度的 10%。divrowbuttoncoldivbuttonbutton

你可以这样做: HTML:

<div class="container flex-grow-1 flex-shrink-0 py-5">
  <div class="mb-5 p-4 bg-white shadow-sm">
    <h1 class="text-center">Plan</h1>
    <div id="stepper1" class="bs-stepper">
      <div class="row mt-5 bs-stepper-header" role="tablist">
        <div class="col d-flex justify-content-center" data-target="#test-l-1">
          <button type="button" class="step-trigger" role="tab" id="stepper1trigger1" aria-controls="test-l-1" aria-selected="true">
            <span class="bs-stepper-circle">1</span>
          </button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>2</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>3</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>4</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>5</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>6</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>7</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>8</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>9</button>
        </div>
        <div class="col d-flex justify-content-center">
          <button>10</button>
        </div>
      </div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

您也可以添加 CSS:

button {
  border: none;
  display: flex;
  padding: 5px;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  width: 30px;
  height: 30px;
}
Run Code Online (Sandbox Code Playgroud)

您可以通过这里的官方文档了解有关Bootstrap网格系统的更多信息: https: //getbootstrap.com/docs/5.1/layout/grid/

演示示例: https: //codepen.io/Hitesh_Vadher/pen/xxrdYYb