Ronna Encarnacion
Ronna Encarnacion

Reputation: 13

Center a div vertically?

I'm building a responsive website, and I have a div (named 'wrapper'), that I want to be in the center of the page at all times. I figured out how to center it horizontally, because I have a set width percentage. How would I center this vertically, if I DONT have a set height percentage?

.wrapper{
    width: 50%;
    height: auto;
    margin-left: 25%;
    padding: 3%;
}'

Upvotes: 1

Views: 336

Answers (2)

rtheunissen
rtheunissen

Reputation: 7435

Try this jQuery plugin: TailorFit and check out the demo.

One way you could use it would be like this:

$('#your-div').tailorfit();

Because your height is auto, that alone should do the trick.

Full disclosure - I'm the author of the plugin.

Upvotes: 1

Navnath Godse
Navnath Godse

Reputation: 2225

Try this tutorial
Centering div vertically and horizontally

http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

Upvotes: 2

Related Questions