How to center content in a Bootstrap column?
Use Bootstrap's d-flex justify-content-center align-items-center
inside your column to center content horizontally and vertically:
The d-flex
class transforms the column into a flex container, while justify-content-center
and align-items-center
align the content smack in the center along both axes.
Centering text
For text content, the text-center
class is your tool of choice for horizontally centering:
Working with smaller columns
Teeny-tiny columns like col-xs-1
, which sets column widths to a minimal 8.33%, call for an articulate mix of centering techniques:
The justify-content-center
addition ensures that your content doesn’t shy away to the corner!
Avoiding historical relics
In the world of modern HTML5, the align
attribute sleeps with the dinosaurs. Swear by CSS and Bootstrap classes and avoid using outdated align
for centering.
Perfecting complex centering
For those intricate operations that need text within flex items aligned too, mix up d-flex
, justify-content-center
, and text-center
classes:
Custom flexbox dance
Sometimes, Bootstrap's pre-defined moves might not fit the groove. In such scenarios, let flexbox take the stage with custom classes and properties like my-auto
and flex-direction
:
Controlling the uncontrollable
To control content that might burst out of the boundaries, like jabbering text or balloon-sized images, CSS property word-break: break-all;
can keep things neat:
Was this article helpful?