Home >Web Front-end >CSS Tutorial >How to Vertically Center a Container in Bootstrap Using Flexbox and Traditional Methods?
When working with Bootstrap, it's common to encounter the need for vertical alignment, particularly within the jumbotron component. This article delves into two approaches to achieve this using the flexible box and traditional methods.
With the advent of the flexible box layout, vertical alignment has become significantly simplified. This method leverages the display: flex property and the align-items property set to center.
.vertical-center { min-height: 100vh; display: flex; align-items: center; }
For internet Explorer 8 and 9 compatibility, a traditional approach utilizing pseudo-elements and inline-block elements is recommended. This method involves creating a pseudo-element with a full height, setting its vertical-align to middle, and setting the display of both the pseudo-element and the container element to inline-block.
.vertical-center { height: 100%; text-align: center; font: 0/0 a; } .vertical-center:before { content: " "; display: inline-block; vertical-align: middle; height: 100%; } .vertical-center > .container { max-width: 100%; display: inline-block; vertical-align: middle; font: 16px/1 "Helvetica Neue", Helvetica, Arial, sans-serif; }
The above is the detailed content of How to Vertically Center a Container in Bootstrap Using Flexbox and Traditional Methods?. For more information, please follow other related articles on the PHP Chinese website!