首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用bootstrap在容器内对齐stepper

使用bootstrap在容器内对齐stepper
EN

Stack Overflow用户
提问于 2021-08-31 01:01:56
回答 1查看 426关注 0票数 4

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

我正在使用Bootstrap5

下面是当前的输出:

我正在尝试获取容器内的数字,以下是模板:

代码语言:javascript
复制
    <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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-11 12:09:34

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

你可以这样做: HTML:

代码语言:javascript
复制
<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:

代码语言:javascript
复制
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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68991753

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档