CSS : center form in page horizontally and vertically

后端 未结 6 1608
执念已碎
执念已碎 2020-12-13 01:33

How can i center the form called form_login horizontally and vertically in my page ?

Here is the HTML I\'m using right now:


    
6条回答
  •  自闭症患者
    2020-12-13 01:39

    If you want to do a horizontal centering, just put the form inside a DIV tag and apply align="center" attribute to it. So even if the form width is changed, your centering will remain the same.

    UPDATE

    @G-Cyr is right. align="center" attribute is now obsolete. You can use text-align attribute for this as following.

    This will center all the content inside the parent DIV. An optional way is to use margin: auto CSS attribute with predefined widths and heights. Please follow the following thread for more information.

    How to horizontally center a in another ?

    Vertical centering is little difficult than that. To do that, you can do the following stuff.

    html

    
    

    Css

    #parent {
       display: table;
       width: 100%;
    }
    #form_login {
       display: table-cell;
       text-align: center;
       vertical-align: middle;
    }
    

提交回复
热议问题