html 使用bootstrap在容器内对齐stepper div

xmq68pz9  于 2022-12-25  发布在  Bootstrap
关注(0)|答案(1)|浏览(190)

我在容器内的Stepper中有一个标题图标列表,我尝试让它们响应页面大小的更改,但没有效果。我尝试在不同的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>
1wnzp6jl

1wnzp6jl1#

您可以在div中使用col类,row类用于每个button。它根据屏幕宽度自动调整每个按钮的宽度。使用col类,每个divbutton将占用相等的空间。在我们的示例中,由于有10个button元素,每个占据整个宽度的10%。
你可以这样做:超文本:

<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>

您也可以添加CSS:

button {
  border: none;
  display: flex;
  padding: 5px;
  justify-content: center;
  align-items: center;
  border-radius: 50%;
  width: 30px;
  height: 30px;
}

您可以通过此处的官方文档了解有关Bootstrap网格系统的详细信息:https://getbootstrap.com/docs/5.1/layout/grid/
演示示例:https://codepen.io/Hitesh_Vadher/pen/xxrdYYb

相关问题