Home > Article > Web Front-end > How to Center Content in a Bootstrap Column?
Centering Content in a Bootstrap Column
You're experiencing difficulties centering the content within a Bootstrap column. Your provided HTML includes the following:
<code class="html"><div class="row"> <div class="col-xs-1 center-block"> <span>aaaaaaaaaaaaaaaaaaaaaaaaaaa</span> </div> </div></code>
Solution:
The issue lies in the use of the "center-block" class. This class is no longer supported in current versions of Bootstrap. Instead, you should use one of the following methods:
Before Bootstrap 3:
Use the "align" attribute:
<code class="html"><div class="col-xs-1" align="center"></code>
Bootstrap 3 and 4:
Use the "text-center" class:
<code class="html"><div class="col-xs-1 text-center"></code>
Bootstrap 4:
Use flex classes:
<code class="html"><div class="d-flex justify-content-center"> <div>some content</div> </div></code>
Note: Bootstrap 4 aligns content horizontally by default. For vertical alignment, use "flex-direction: column" on the parent element.
The above is the detailed content of How to Center Content in a Bootstrap Column?. For more information, please follow other related articles on the PHP Chinese website!