Bhuvan InfoTech Android App

Download our Android App and browse Technical News, Projects, Computer Tricks more easily with lots of Interesting Features.

Wednesday, April 25, 2018

How to Align div to the middle of page.


To align div to the middle of the screen or to align any element to the center of screen. you have to add following css to your stylesheet.

left: 50%;
top: 50%;
transform: translate(-50%, -50%);


How it works ?


The CSS left property is based on the size of the parent element. The transform property is based on the size of the target element.
50% to the left moves element to the center of parent screen.
transform -50% moves the element back with respect to half of its own width.
So by this strategy above css align element to the center of screen.

Bhuvan Arora

No comments:

Amazing Deal !