![]() |
Flexbox can be used to align HTML elements with ease, making it a powerful tool for responsive design. By utilizing Flexbox properties, you can centre a button both horizontally and vertically within its container, or adjust its alignment to achieve specific layouts. These are the following ways to centre a button: Table of Content Center Button Horizontally and Vertically in the Parent ContainerIn this approach, we are using Flexbox to center the button both horizontally and vertically within its parent container. The body element is set as a flex container to center the .container div in the viewport. The .container itself is a flex container with its content (the button) centered using justify-content: center and align-items: center. Example: The below example Center Button Horizontally and Vertically in the Parent Container.
Output: ![]() Output Center Button Horizontally in the Parent Container and Vertically Align at the BottomIn this approach, we are using Flexbox to center the button horizontally within its parent container and align it at the bottom vertically. The body is set up as a flex container to center the .container div in the viewport. Inside .container, the flex-direction: column property stacks its children vertically, while justify-content: flex-end pushes the button to the bottom, and align-items: center centers it horizontally. Example: The below example Center Button Horizontally in the Parent Container and Vertically Align at the Bottom.
Output: ![]() Output |
Reffered: https://www.geeksforgeeks.org
CSS |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 24 |