<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-8">
<div v-for="job in job">
<div class="text-center">
<h1>{{ job.job_title }}</h1>
<p><strong>Google Inc. </strong> - {{ job.location }}</p>
<h2><u>Job Description</u></h2>
</div>
<p v-html="desc"></p>
<p class="text-center">Posted: {{ formatDate(job.date_created) }}</p>
<button v-on:click="applyResume()" id="apply-btn" class="btn btn-primary">{{ buttonText }}</button>
</div>
</div>
<div class="hidden-sm-down col-md-4"></div>
</div>
</div>
不知道如何让这个按钮居中。在 BS 3 中,我只会使用中心 block ,但这在 BS4 中不是一个选项。有什么建议吗?
最佳答案
在 Bootstrap 4 中,应该使用 text-center
类来对齐 inline-blocks。
注意:在您应用于父元素的自定义类中定义的 text-align:center;
将起作用,无论您使用的是哪个 Bootstrap 版本。而这正是 .text-center
适用的。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col text-center">
<button class="btn btn-default">Centered button</button>
</div>
</div>
</div>
如果要居中的内容是block或flex(不是inline-
),可以使用 flexbox 将其居中:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<div class="d-flex justify-content-center">
<button class="btn btn-default">Centered button</button>
</div>
... 应用 display: flex;证明内容:居中
到父级。
注意:不要使用 .row.justify-content-center
而不是 .d-flex.justify-content-center
,因为 .row
在某些响应间隔上应用负边距,这会导致意外的水平滚动条(除非 .row
是 .container
的直接子级,它在正确的响应间隔上应用横向填充来抵消负边距)。如果你必须使用 .row
,无论出于什么原因,用 .m-0.p-0
覆盖它的边距和填充,在这种情况下你最终会得到几乎与 .d-flex
相同的样式。
重要说明:当居中内容(按钮)超过父级(.d-flex
)的宽度时,尤其是当父级有视口(viewport)宽度,特别是因为它无法水平滚动到内容的开头(最左侧)。
因此,当要居中的内容可能变得比可用的父宽度更宽并且所有内容都应该可以访问时,不要使用它。
关于css - Bootstrap 4,如何使按钮居中对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41664991/