iCodeLikeImDrunk
iCodeLikeImDrunk

Reputation: 17806

how to center a form using css?

Literally centering on ALL four sides. I see lots of tutorials just using

element.style.margin = "0 auto";

This only centers it on the X-Axis, but not the Y-axis.

How do I get it to center via Y-Axis as well?

Upvotes: 0

Views: 843

Answers (2)

Ennui
Ennui

Reputation: 10190

Set display: table-cell and vertical-align: middle on the element you want vertically centered and set display: table on its parent container element you want it centered inside of.

Upvotes: 0

johnwinter
johnwinter

Reputation: 3624

I've used:

#myItem {
   position: fixed;
   top: 50%;
   left: 50%;
   width: 100px;
   height: 100px;
   margin-top: -50px;
   margin-left: -50px;
}

.... before, hope it helps

Upvotes: 2

Related Questions