【问题标题】:Aligning stepper divs inside a container using bootstrap使用引导程序在容器内对齐步进器 div
【发布时间】:2021-10-29 15:45:48
【问题描述】:

我在容器内的步进器中有一个标题图标列表,我试图让它们响应页面大小的变化,但它不起作用。我曾尝试在不同的 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>

【问题讨论】:

  • 我们需要 bootstrap 版本和“工作”示例。

标签: html bootstrap-5


【解决方案1】:

对于每个button,您可以在div 中使用col 类和row 类。它会根据屏幕的宽度自动调整每个按钮的宽度。使用col 类,每个divbutton 将占用相同的空间。在我们的例子中,因为有 10 个button 元素,每个元素占据整个宽度的 10%。

你可以这样做: 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>

您也可以添加 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

【讨论】:

    猜你喜欢
    • 2013-11-20
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 2018-08-05
    • 2019-01-29
    • 1970-01-01
    • 2017-11-30
    • 2021-03-10
    相关资源
    最近更新 更多