html - Bootstrap 4 center-block 无法居中

标签 html css twitter-bootstrap bootstrap-4

我有以下 Bootstrap html 代码(它的 JSX 因此 className 但想法是一样的):

<div className="toggleView btn-group center-block" role="group" aria-label="Basic example">
        <button onClick={this.handleTimelineClick} type="button" className={this.state.toggleCalendar == false ? "btn btn-secondary active" : "btn btn-secondary"}>Timeline</button>
        <button onClick={this.handleCalendarClick} type="button" className={this.state.toggleCalendar == true ? "btn btn-secondary active " :"btn btn-secondary"}>Calendar</button>
 </div>

我正在尝试使用 bootstrap center-block 或 CSS 将这段代码居中,但似乎无法让它工作:

enter image description here

绿色条突出显示 div toggleView

我唯一使用的 css 如下:

.toggleView {
    padding: 20px;
}

为什么我不能让这个按钮组居中?

最佳答案

btn-groupdisplay:inline-block所以你会使用 text-center在父容器中..

http://codeply.com/go/hyUYkUrtRN

注意:在 Bootstrap 4 中,center-block现在是mx-auto , 代表 margin: 0 auto;定心 display:block元素。 Bootstrap 4 现在有一个 d-block类也是如此,因此可以使内联元素显示:像这样的 block ..

<img src=".." class="d-block mx-auto" >

另见:Center the content inside a column in Bootstrap 4

关于html - Bootstrap 4 center-block 无法居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38251191/

相关文章:

jquery - CSS 日期选择器

javascript - 在垂直中间概率显示图像悬停 div

jquery - 具有不同边距的 CSS nth Div

CSS 显示 : box with box-align stretch and center at the same time

html - 在链接上设置背景图片以显示在文本链接的右侧

html - BootStrap 小型设备,切换菜单背景颜色

html - 将鼠标悬停在导航栏图标上时,如何阻止它们消失?使用 Bootstrap

javascript - GitHub Pages + Jekyll + Bootstrap + CDN问题

css - 添加其他 div 时,标题 div 会更改其位置

javascript - 带有查询参数的表单提交