Html 如何在引导程序 4 中居中卡片?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39031224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to center cards in bootstrap 4?
提问by Vaibhav Singh
I am using bootstrap 4 alpha 3.
I want to center the card horizontally in the middle across the page.
我正在使用 bootstrap 4 alpha 3。
我想将卡片水平居中放置在页面中间。
Preview / link:
http://codepen.io/vaibhavsingh97/full/VjRAXW
Preview / link:
http://codepen.io/vaibhavsingh97/full/VjRAXW
I have tried all the different options listed on the bootstrap 4 example page for cards.
我已经尝试了 bootstrap 4 示例页面上列出的所有不同选项卡。
How can I achieve this?
我怎样才能做到这一点?
回答by Shahil M
回答by Zim
Update 2018
2018 年更新
There is no need for extra CSS, and there are multiple centeringmethods in Bootstrap 4:
不需要额外的CSS,Bootstrap 4中有多种居中方法:
text-center
for centerdisplay:inline
elementsmx-auto
for centeringdisplay:block
elements insidedisplay:flex
(d-flex)offset-*
ormx-auto
can be used to center grid columns- or
justify-content-center
onrow
to center grid columns
text-center
对于中心display:inline
元素mx-auto
用于将display:block
内部元素居中display:flex
(d-flex)offset-*
或mx-auto
可用于使网格列居中- 或
justify-content-center
上row
至中心格列
mx-auto
(auto x-axis margins) will center inside display:flex
elements that have a defined width, (%, vw, px, etc..). Flexbox is used by default on grid columns, so there are also various centering methods.
mx-auto
(自动 x 轴边距)将在display:flex
具有定义宽度(%、vw、px 等)的元素内部居中。Flexbox 默认用于网格列,因此也有各种居中方法。
In your case, you can simply mx-auto
to the card
s.
在您的情况下,您可以简单地mx-auto
转到card
s。
回答by bharti parmar
You can also use Bootstrap 4 flex classes
您还可以使用 Bootstrap 4 flex 类
Like: .align-item-center, .justify-content-center
We can use this classes identically for all device view.
我们可以对所有设备视图相同地使用这些类。
Like .align-iten-sm-center, .align-item-md-center, .justify-content-xl-center, .justify-content-lg-center, .justify-content-xs-center
.text-center class is used to align text in center.
.text-center 类用于将文本居中对齐。