问题描述
我需要帮助解决此问题,我需要将内容居中放在bootstrap4的列中,请在下面找到我的代码
I Need help to fix the problem, I need to center the content inside the column in bootstrap4, please find my code below
<div class="container">
<div class="row justify-content-center">
<div class="col-3">
<div class="nauk-info-connections">
</div>
</div>
</div>
推荐答案
在Bootstrap 4中有多种水平居中方法 ...
There are multiple horizontal centering methods in Bootstrap 4...
-
text-center
用于中心display:inline
个元素 -
offset-*
或mx-auto
可用于中心列(col-*
) - 或
row
上的justify-content-center
到中心列(col-*
) -
mx-auto
用于将display:block
元素居中于d-flex
text-center
for centerdisplay:inline
elementsoffset-*
ormx-auto
can be used to center column (col-*
)- or,
justify-content-center
on therow
to center columns (col-*
) mx-auto
for centeringdisplay:block
elements insided-flex
mx-auto
(自动x轴边距)将使具有定义宽度(%,vw,px等)的display:block
或display:flex
元素居中.默认情况下,在网格列上使用Flexbox,因此还有多种flexbox居中方法.
mx-auto
(auto x-axis margins) will center display:block
or display:flex
elements that have a defined width, (%, vw, px, etc..). Flexbox is used by default on grid columns, so there are also various flexbox centering methods.
在您的情况下,请使用mx-auto
将col-3
居中,并使用text-center
将其内容居中.
In your case, use mx-auto
to center the col-3
and text-center
to center it's content..
<div class="row">
<div class="col-3 mx-auto">
<div class="text-center">
center
</div>
</div>
</div>
https://codeply.com/go/GRUfnxl3Ol
或 ,在弹性框元素(.row
)上使用justify-content-center
:
<div class="container">
<div class="row justify-content-center">
<div class="col-3 text-center">
center
</div>
</div>
</div>
另请参阅:
Bootstrap 4中的垂直对齐中心
Also see:
Vertical Align Center in Bootstrap 4
这篇关于将内容居中放在Bootstrap 4的列中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!