html - 如何移动html中中间的按钮?

标签 html bootstrap-4

我的代码是这样的,我尝试了几次将按钮移到中间但失败了。我应该如何修改代码来更改按钮的位置?它总是在最左边。谢谢!

<div class="jumbotron">
    <h1 align="center">Bucket List App</h1>
    <p class="lead"></p>
    <p><a class="btn btn-lg btn-success" href="showSignUp" role="button" style="width:200px">Sign up today</a></p>
</div>

最佳答案

最简单的方法是使用 Flex 类d-flex justify-content-center。查看下面的代码:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">


<div class="jumbotron">
    <h1 align="center">Bucket List App</h1>
    <p class="lead"></p>
    <div class="d-flex justify-content-center">
    	<a class="btn btn-lg btn-success" href="showSignUp" role="button" style="width:200px">Sign up today</a>
    </div>
</div>

如果您想对齐所有元素,可以向 jumbotron 添加 d-flex flex-columnalign-items-center 类。这取决于您的需要。

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">


<div class="jumbotron d-flex flex-column align-items-center">
  <h1>Bucket List App</h1>
  <p class="lead"></p>
  <div>
    <a class="btn btn-lg btn-success" href="showSignUp" role="button" style="width:200px">Sign up today</a>
  </div>
</div>

关于html - 如何移动html中中间的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57529759/

相关文章:

javascript - 为什么 window.scrollTo() 没有被调用?

jquery - 元素溢出父元素并且滚动不起作用

jquery - 使用多日期日期选择器限制所选日期

jquery - Bootstrap 的侧边栏带有固定页脚和可滚动 div

css - 带进度条的引导输入组

html - 移动布局中的 Div 顺序 - Bootstrap 4 行和列

java - 为什么struts2 html table会多生成一个<tr></tr>

html - 图像视差全窗口显示

html - 使用 css 不显示背景图像

javascript - 单选按钮不起作用 - AngularJS