简体   繁体   中英

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?

I've used:

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

.... before, hope it helps

在要垂直居中的元素上设置display: table-cellvertical-align: middle ,并在其父级容器元素上设置display: table ,使其居中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM