
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Horizontal and Vertical Center Alignment with Flexbox in CSS3
For horizontal and vertical center alignment with Flexbox, use the align-items property in CSS3. Set the align-items property to center.
Following is the code for horizontal and vertical center alignment with flexbox −
Example
<!DOCTYPE html> <html> <head> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .h-container { display: flex; width: 300px; height: 300px; background-color: lightblue; justify-content: center; align-items: center; border: 2px solid black; } .h-1 { font-size: 30px; width: 150px; height: 150px; background-color: red; color: white; border: 2px solid rgb(58, 2, 83); } </style> </head> <body> <h2>Horizontal and vertical center alignment using flexbox</h2> <div class="h-container"> <div class="h-1">Centered Div</div> </div> </body> </html>
Output
The above code will produce the following output −
- Related Articles
- CSS Central, Horizontal and Vertical Alignment
- Flexbox and vertical scroll in a full-height app using newer Flexbox API with HTML
- Vertical Text, with Horizontal Letters in CSS
- Center one and right/left align other flexbox element in HTML
- Distribute extra horizontal and vertical space in a GridBagLayout with Java
- How to set the horizontal alignment of text with JavaScript?
- Center alignment using the margin property in CSS
- Difference between Horizontal and Vertical Relationships
- How to set the horizontal alignment of an element with JavaScript?
- Vertical alignment of an image using CSS
- Vertical and Horizontal Scrollbars on Tkinter Widget
- Difference between vertical integration and horizontal integration
- Difference between Horizontal Equity and Vertical Equity
- How to align flexbox container into center using JavaScript?
- How to set the vertical alignment of the content in an element with JavaScript?

Advertisements