首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带Bootstrap的HTML :按钮右对齐,div在新行居中

带Bootstrap的HTML :按钮右对齐,div在新行居中
EN

Stack Overflow用户
提问于 2020-08-18 17:48:29
回答 1查看 52关注 0票数 0

在我的网页中(使用Bootstrap),我需要在新的一行中显示一个右对齐的按钮和一个居中的微调器。

但我把旋转器放在同一条线上,在剩下的线上居中...

我的代码:

代码语言:javascript
复制
<div>
  <button type="button" class="btn btn-primary mt-4 float-right">Text</button>
</div>  

<div class="text-center mt-4">
  <div class="spinner-border" role="status"></div>
</div>

我做错了什么?

谢谢,

迭戈

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-18 19:36:05

您可以使用Bootstrap's grid system并定义两个具有全宽列的行。我将margin-top mt-4移到了第二个.row,以便为整行提供该边距。

代码语言:javascript
复制
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col">
      <button type="button" class="btn btn-primary mt-4 float-right">Text</button>
    </div>
  </div>
  <div class="row mt-4">
    <div class="col text-center">
      <div class="spinner-border" role="status"></div>
    </div>
  </div>  
</div>

为了将您的<button>放在最右边,只需移除<div class="container">即可。有关更多信息,请阅读this

当然,还有其他几种选择来接收期望的结果,例如,使用equal-width multi-lines

代码语言:javascript
复制
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col">
      <button type="button" class="btn btn-primary mt-4 float-right">Text</button>
    </div>
    <div class="w-100"></div>
    <div class="col mt-4 text-center">
      <div class="spinner-border" role="status"></div>
    </div>
  </div>  
</div>

祝好运!

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

https://stackoverflow.com/questions/63466073

复制
相关文章

相似问题

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