Proper way to center a div

This question already has an answer here:

  • Center a column using Twitter Bootstrap 3 28 answers

  • If what you are asking is how you can vertically center content in a div, you can use display: flex;

    Try this:

    .site-wrapper {
         height: 75%;
         display: flex;
         align-items: center; /*Horizontally centers content*/
         justify-content: center; /*Vertically centers content*/
         flex-direction: column; /* Makes content in div to flow under instead of side by side*/
     }
    

    div元素是一个块元素,因此如果你想水平居中,最简单的方法就是使用margin自动方法。

    .site-wrapper{
     width:1200px; //you have to give specific width value
     margin: 0 auto;}
    
    链接地址: http://www.djcxy.com/p/75908.html

    上一篇: 在包装中的中心表单

    下一篇: 适当的方法来中心div