VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-position-center-elements/

⇱ Bootstrap 5 Position Center elements - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Position Center elements

Last Updated : 29 Jul, 2024

Bootstrap 5 Position Center elements facilitate aligning the elements to the absolute center by implementing the transform utility class .translate-middle, which implements the transformations translateX(-50%) & translateY(-50%) to the element, along with combining the edge positioning utilities. Bootstrap 5 provides the 3 different transform utility classes that help to align the elements to the center.

Position Center elements Classes:

ClassDescription
translate-middleAlign the element to the center vertically and horizontally.
translate-middle-xPositions the element horizontally to the center while maintaining its vertical position.
translate-middle-yPositions the element vertically to the center while maintaining its horizontal position.

Syntax: 

<div class="position-relative">
...
</div>

Example 1: This example describes the Bootstrap Position Center Elements by implementing classes like position-absolute top-50 start-50 translate-middle.

Output:

👁 Bootstrap-5-Position-Center-elements
Bootstrap 5 Position Center elements Example Output


Example 2: This example describes the use of the Position Center elements in Bootstrap5, by implementing the .translate-middle, .translate-middle-x, & .translate-middle-y classes.

Output:

👁 Bootstrap-5-Position-Center-elements-2
Bootstrap 5 Position Center elements Example Output
Comment

Explore