Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Center a 'div' vertically in a % height 'div'

Tags:

html

css

Is it possible to center a div vertically in a % height div?

like image 256
Hailwood Avatar asked Jul 29 '10 14:07

Hailwood


People also ask

How do I vertically center a div in another div?

Vertically centering div items inside another div Just set the container to display:table and then the inner items to display:table-cell . Set a height on the container, and then set vertical-align:middle on the inner items.

How do I align content vertically centered?

To center both vertically and horizontally, use padding and text-align: center : I am vertically and horizontally centered.


1 Answers

This has been asked enough times here as well as all over the Internet.

A quick search will bring you tons of results. Anyhow, my preferred way of doing this is to use display: table-cell; and vertical-align: middle;. See this page for an example. (Beware that this doesn't work on Internet Explorer 6.)

like image 160
casablanca Avatar answered Sep 22 '22 19:09

casablanca