Why should I use a container div in HTML?

前端 未结 9 1692
陌清茗
陌清茗 2020-12-23 14:33

I have noticed a common technique is to place a generic container div in the root of the body tag:


  
    ...
  
  <         


        
9条回答
  •  别那么骄傲
    2020-12-23 14:50

    I know this is an old question, but i faced this issue myself redesigning a website. Troy Dalmasso got me thinking. He makes a good point. So, i started to see if i could get it working without a container div.

    I could when i set the width of the body. In my case to 960px.

    This is the css i use:

    html {
      text-align:center;
    }
    
    body {
      margin: 0 auto;
      width: 960px;
    }
    

    This nicely centers the inline-blocks which also have a fixed width.

    Hope this is of use to anyone.

提交回复
热议问题