Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
How can I vertically center a div element for all browsers using CSS?
To vertically center a div element for all browsers using CSS, use the Flexbox. CSS3 provides another layout mode Flexible Box, commonly called as Flexbox. Using this mode, you can easily create layouts for complex applications and web pages. Unlike floats, Flexbox layout gives complete control over the direction, alignment, order, size of the boxes.
The To vertically centre a div, we will use the flex property, the align-items property. The value is set to center to center the div. In the below example, we have set one of the divs to align center using the align-items property with the value center ? The content is then set in the same div demo2 to center align ? Archery is a bow and arrow game where each player is supposed to shoot arrows from a bow and hit a fixed target. Let us now see the example to vertically center a div element for all browsers using CSS ?demo2 {
display: flex;
align-items: center;
height: 60%;
}
Example
